<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>js概念与类型检测判断题 | 孙志豪的博客</title><meta name="author" content="孙志豪"><meta name="copyright" content="孙志豪"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="js概念与类型检测 以下不属于 typeof 运算符返回值的是？  12345A. &quot;string&quot;B. &quot;function&quot;C. &quot;object&quot; D. &quot;null&quot;     执行以下代码，错误的输出结果是  12345A. 输入：typeof &amp;#123;&quot;x&quot;:1&amp;#125; 输出：&amp;quo">
<meta property="og:type" content="article">
<meta property="og:title" content="js概念与类型检测判断题">
<meta property="og:url" content="https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/js%E7%AC%94%E8%AF%95%E9%A2%98/index.html">
<meta property="og:site_name" content="孙志豪的博客">
<meta property="og:description" content="js概念与类型检测 以下不属于 typeof 运算符返回值的是？  12345A. &quot;string&quot;B. &quot;function&quot;C. &quot;object&quot; D. &quot;null&quot;     执行以下代码，错误的输出结果是  12345A. 输入：typeof &amp;#123;&quot;x&quot;:1&amp;#125; 输出：&amp;quo">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://szhihao.gitee.io/img/%E5%A4%A9%E7%A9%BA.jpeg">
<meta property="article:published_time" content="2022-10-11T12:01:36.000Z">
<meta property="article:modified_time" content="2022-10-11T09:29:37.275Z">
<meta property="article:author" content="孙志豪">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://szhihao.gitee.io/img/%E5%A4%A9%E7%A9%BA.jpeg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/js%E7%AC%94%E8%AF%95%E9%A2%98/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","languages":{"hits_empty":"We didn't find any results for the search: ${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'js概念与类型检测判断题',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-10-11 17:29:37'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/%E5%A4%B4%E5%83%8F.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">44</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">15</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/%E5%A4%A9%E7%A9%BA.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">孙志豪的博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> Search</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">js概念与类型检测判断题</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2022-10-11T09:29:37.275Z" title="Updated 2022-10-11 17:29:37">2022-10-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/">核心js（手写篇）</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="js概念与类型检测判断题"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><hr>
<h4 id="js概念与类型检测"><a href="#js概念与类型检测" class="headerlink" title="js概念与类型检测"></a>js概念与类型检测</h4><ol>
<li>以下不属于 typeof 运算符返回值的是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="string">&quot;string&quot;</span></span><br><span class="line">B. <span class="string">&quot;function&quot;</span></span><br><span class="line">C. <span class="string">&quot;object&quot;</span> </span><br><span class="line">D. <span class="string">&quot;null&quot;</span>  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>执行以下代码，错误的输出结果是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 输入：<span class="keyword">typeof</span> &#123;<span class="string">&quot;x&quot;</span>:<span class="number">1</span>&#125; 输出：<span class="string">&quot;object&quot;</span> </span><br><span class="line">B. 输入：<span class="keyword">typeof</span> <span class="number">1</span> 输出：<span class="string">&quot;number&quot;</span> </span><br><span class="line">C. 输入：<span class="keyword">typeof</span> [&#123;<span class="attr">x</span>:<span class="number">1</span>&#125;] 输出：<span class="string">&quot;array&quot;</span> </span><br><span class="line">D. 输入：<span class="keyword">typeof</span> <span class="title class_">NaN</span> 输出：<span class="string">&quot;number&quot;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>可以用typeof来判断的基本类型有</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="literal">undefined</span></span><br><span class="line">B. <span class="literal">null</span>  </span><br><span class="line">C. array   </span><br><span class="line">D. object </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下不属于JavaScript基本数据类型的是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Boolean</span></span><br><span class="line">B. <span class="literal">undefined</span></span><br><span class="line">C. <span class="title class_">Symbol</span>  </span><br><span class="line">D. <span class="title class_">Array</span>  </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下关于JavaScript中数据类型的说法错误的是()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 数据类型分为基本数据类型和引用数据类型</span><br><span class="line">B. <span class="title class_">JavaScript</span>一共有<span class="number">8</span>种数据类型 </span><br><span class="line">C. <span class="title class_">Object</span>是引用数据类型，且只存储于堆(heap)中</span><br><span class="line">D. <span class="title class_">BigInt</span>是可以表示任意精度整数的基本数据类型，存储于栈(stack)中</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">DCADC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="逻辑判断"><a href="#逻辑判断" class="headerlink" title="逻辑判断"></a>逻辑判断</h4><ol>
<li>请选择结果为ture的表达式？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="literal">null</span> <span class="keyword">instanceof</span> <span class="title class_">Object</span>  </span><br><span class="line">B. <span class="literal">null</span> === <span class="literal">undefined</span></span><br><span class="line">C. <span class="literal">null</span> == <span class="literal">undefined</span></span><br><span class="line">D. <span class="title class_">NaN</span> == <span class="title class_">NaN</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列代码结果为 true 的是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Symbol</span>.<span class="title function_">for</span>(<span class="string">&#x27;a&#x27;</span>) === <span class="title class_">Symbol</span>.<span class="title function_">for</span>(<span class="string">&#x27;a&#x27;</span>)</span><br><span class="line">B. <span class="title class_">Symbol</span>(<span class="string">&#x27;a&#x27;</span>) === <span class="title class_">Symbol</span>(<span class="string">&#x27;a&#x27;</span>)</span><br><span class="line">C. <span class="title class_">NaN</span> === <span class="title class_">NaN</span></span><br><span class="line">D. &#123;&#125; === &#123;&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>根据如下变量，下列表达式中返回值为true的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">var</span> b = [];</span><br><span class="line"><span class="keyword">var</span> c = <span class="string">&#x27;&#x27;</span>;</span><br><span class="line"><span class="keyword">var</span> d = <span class="literal">true</span>;</span><br><span class="line"></span><br><span class="line">A. (a || b) === <span class="literal">true</span></span><br><span class="line">B. (b &amp;&amp; c) === <span class="literal">true</span></span><br><span class="line">C. (c &amp;&amp; d) === <span class="literal">true</span></span><br><span class="line">D. (d || a) === <span class="literal">true</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>1&#x3D;&#x3D;true的返回值是true，这句话是否正确？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">A. T</span><br><span class="line">B. F</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面代码输出为true的是?</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="variable language_">console</span>.<span class="title function_">log</span>([] === []);</span><br><span class="line">B. <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="literal">undefined</span> == <span class="number">0</span>);</span><br><span class="line">C. <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="literal">undefined</span> == <span class="literal">false</span>);</span><br><span class="line">D. <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="literal">false</span> == <span class="string">&#x27;&#x27;</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>浏览器环境下，以下打印结果为true的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;12&quot;</span> === <span class="number">12</span>)</span><br><span class="line">B. <span class="variable language_">console</span>.<span class="property">log</span> (<span class="title class_">NaN</span> === <span class="title class_">NaN</span>)</span><br><span class="line">C. <span class="variable language_">console</span>.<span class="property">log</span> (<span class="title function_">typeof</span>(<span class="literal">null</span>) === <span class="title function_">typeof</span>(<span class="variable language_">window</span>))</span><br><span class="line">D. <span class="variable language_">console</span>.<span class="property">log</span> ([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>] === [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>注意浏览器环境与node环境的差别，比如C选项</strong></p>
<ol>
<li>以下表达式，正确的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Number</span>(<span class="string">&#x27;a&#x27;</span>) == <span class="title class_">Number</span>(<span class="string">&#x27;a&#x27;</span>)</span><br><span class="line">B. -<span class="number">1</span> == <span class="literal">true</span></span><br><span class="line">C. <span class="number">3</span> + <span class="string">&#x27;2&#x27;</span> === <span class="number">5</span></span><br><span class="line">D. ![] == <span class="string">&#x27;&#x27;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">CADADCD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="Math"><a href="#Math" class="headerlink" title="Math"></a>Math</h4><ol>
<li>如何把 7.25 四舍五入为最接近的整数</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Math</span>.<span class="title function_">round</span>(<span class="number">7.25</span>)</span><br><span class="line">B. <span class="title class_">Math</span>.<span class="title function_">ceil</span>(<span class="number">7.25</span>)</span><br><span class="line">C. <span class="title function_">round</span>(<span class="number">7.25</span>)</span><br><span class="line">D. <span class="title class_">Math</span>.<span class="title function_">rnd</span>(<span class="number">7.25</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面哪个选项可以产生0&lt;&#x3D;num&lt;&#x3D;10的随机整数</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Math</span>.<span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*<span class="number">6</span>)</span><br><span class="line">B. <span class="title class_">Math</span>.<span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*<span class="number">10</span>)</span><br><span class="line">C. <span class="title class_">Math</span>.<span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*<span class="number">11</span>)</span><br><span class="line">D. <span class="title class_">Math</span>.<span class="title function_">ceil</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*<span class="number">10</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下( )表达式产生一个0~7之间(含0,7)的随机整数</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Math</span>.<span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*<span class="number">6</span>)</span><br><span class="line">B. <span class="title class_">Math</span>.<span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*<span class="number">7</span>)</span><br><span class="line">C. <span class="title class_">Math</span>. <span class="title function_">floor</span>(<span class="title class_">Math</span>.<span class="title function_">random</span>()*<span class="number">8</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">A <span class="title function_">CD</span>(注意D) C</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h4><ol>
<li>split() 方法用于把一个字符串分割成字符串数组。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">A. T</span><br><span class="line">B. F</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>String对象的哪个方法可以寻找子字符串并返回该子字符串位置</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title function_">match</span>()</span><br><span class="line">B. <span class="title function_">indexOf</span>()</span><br><span class="line">C. <span class="title function_">search</span>()</span><br><span class="line">D. <span class="title function_">concat</span>()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">A <span class="variable constant_">BC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="JSON"><a href="#JSON" class="headerlink" title="JSON"></a>JSON</h4><ol>
<li>下面哪一个是JSON数据？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. ｛<span class="attr">name</span>:<span class="string">&quot;xiaoming&quot;</span>,age,<span class="string">&quot;student&quot;</span>｝</span><br><span class="line">B. ｛<span class="string">&quot;name&quot;</span>:<span class="string">&quot;xiaoming&quot;</span>,<span class="string">&quot;age&quot;</span>:<span class="string">&quot;student&quot;</span>｝</span><br><span class="line">C. ｛<span class="string">&quot;xiaoming&quot;</span>,<span class="string">&quot;student&quot;</span>｝</span><br><span class="line">D. [<span class="string">&quot;xiaoming&quot;</span>,<span class="string">&quot;student&quot;</span>]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面分别使用 JSON.stringify 方法，返回值 res 分别是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> fn = <span class="keyword">function</span>(<span class="params"></span>)&#123;&#125;</span><br><span class="line"><span class="keyword">const</span> res = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(fn)</span><br><span class="line"><span class="keyword">const</span> num = <span class="number">123</span></span><br><span class="line"><span class="keyword">const</span> res = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(num)</span><br><span class="line"><span class="keyword">const</span> res = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(<span class="title class_">NaN</span>)</span><br><span class="line"><span class="keyword">const</span> b = <span class="literal">true</span></span><br><span class="line"><span class="keyword">const</span> res = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(b)</span><br><span class="line"></span><br><span class="line">A. <span class="string">&#x27;function&#x27;</span>、<span class="string">&#x27;123&#x27;</span>、<span class="string">&#x27;NaN&#x27;</span>、<span class="string">&#x27;true&#x27;</span></span><br><span class="line">B. <span class="literal">undefined</span>、<span class="string">&#x27;123&#x27;</span>、<span class="literal">undefined</span>、<span class="string">&#x27;true&#x27;</span></span><br><span class="line">C. <span class="literal">undefined</span>、<span class="string">&#x27;123&#x27;</span>、<span class="string">&#x27;null&#x27;</span>、<span class="string">&#x27;true&#x27;</span></span><br><span class="line">D. <span class="literal">undefined</span>、<span class="string">&#x27;123&#x27;</span>、<span class="string">&#x27;null&#x27;</span>、<span class="literal">undefined</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">BC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h4><ol>
<li>js数组中不会改变原有数组的方法是()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. push</span><br><span class="line">B. concat</span><br><span class="line">C. sort</span><br><span class="line">D. shift</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列哪种数组的方法不会修改数组本身</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. slice</span><br><span class="line">B. splice</span><br><span class="line">C. sort</span><br><span class="line">D. unshift</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>JavaScript中需要往数组末尾处添加一个元素，应该使用以下哪个方法：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. push</span><br><span class="line">B. pop</span><br><span class="line">C. shift</span><br><span class="line">D. unshift</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下js操作Array的方法中不能添加元素的是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. push</span><br><span class="line">B. pop</span><br><span class="line">C. unshift</span><br><span class="line">D. splice</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>数组以下哪个方法会影响原数组？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. concat</span><br><span class="line">B. splice</span><br><span class="line">C. slice</span><br><span class="line">D. join</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>JavaScript中，下列哪一个Array的方法的返回值类型和其他不同</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. concat</span><br><span class="line">B. shift</span><br><span class="line">C. filter</span><br><span class="line">D. map</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>如下的Array.prototype上的方法中，那个方法不会改变原有的数组？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. push</span><br><span class="line">B. slice</span><br><span class="line">C. splice</span><br><span class="line">D. sort</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>对于一个数字组成的数组 nums，现在需要执行在不改动 nums 的基础上去重操作，返回一个新的无重复元素的数组，以下几段代码能完成这一操作的是()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// (1)</span></span><br><span class="line"><span class="keyword">const</span> newNums = <span class="title class_">Array</span>.<span class="title function_">from</span>(<span class="keyword">new</span> <span class="title class_">Set</span>(nums))</span><br><span class="line"></span><br><span class="line"><span class="comment">// (2)</span></span><br><span class="line"><span class="keyword">const</span> newNums = nums.<span class="title function_">filter</span>(<span class="function">(<span class="params">n, i</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> nums.<span class="title function_">indexOf</span>(n) === i</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// (3)</span></span><br><span class="line"><span class="keyword">const</span> newNums = nums.<span class="title function_">forEach</span>(<span class="function">(<span class="params">n, i</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> nums.<span class="title function_">indexOf</span>(n) === i</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// (4)</span></span><br><span class="line"><span class="keyword">const</span> newNums = nums.<span class="title function_">reduce</span>(<span class="function">(<span class="params">acc, n, i</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> [].<span class="title function_">concat</span>(acc, nums.<span class="title function_">indexOf</span>(n) === i ? n : []</span><br><span class="line">)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">A. (<span class="number">1</span>)、(<span class="number">2</span>)、(<span class="number">3</span>)、(<span class="number">4</span>)</span><br><span class="line">B. (<span class="number">1</span>)、(<span class="number">3</span>)、(<span class="number">4</span>)</span><br><span class="line">C. (<span class="number">1</span>)、(<span class="number">2</span>)、(<span class="number">4</span>)</span><br><span class="line">D. (<span class="number">1</span>)、(<span class="number">4</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">BAABB</span></span><br><span class="line"><span class="variable constant_">BBC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="正则"><a href="#正则" class="headerlink" title="正则"></a>正则</h4><ol>
<li>正则表达式 ^d+[^d]+ 能匹配下列哪个字符串？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="number">123</span></span><br><span class="line">B. 123a</span><br><span class="line">C. d123</span><br><span class="line">D. 123def</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面哪个不是RegExp对象的方法</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. test</span><br><span class="line">B. match</span><br><span class="line">C. exec</span><br><span class="line">D. compile</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下哪项可以去除变量str中的所有空格</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. str.<span class="title function_">replace</span>(<span class="string">`/\s*/g,&quot;&quot;`</span>)</span><br><span class="line">B. str.<span class="title function_">replace</span>(<span class="string">`/^\s|\s$/g,&quot;&quot;`</span>)</span><br><span class="line">C. str.<span class="title function_">replace</span>(<span class="string">`/^\s*/, &quot;&quot;`</span>)</span><br><span class="line">D. str.<span class="title function_">replace</span>(<span class="string">`/(\s*$)/g, &quot;&quot;`</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">CBA</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h4><ol>
<li>下列函数哪个不是JavaScript的全局函数</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="built_in">encodeURI</span></span><br><span class="line">B. <span class="built_in">parseFloat</span></span><br><span class="line">C. round</span><br><span class="line">D. <span class="built_in">eval</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>编写高性能JavaScript，以下描述错误的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 遵循严格模式：<span class="string">&quot;use strict&quot;</span></span><br><span class="line">B. 将js脚本放在页面顶部，加快渲染页面</span><br><span class="line">C. 将js脚本成组打包，减少请求，尽量减少使用闭包</span><br><span class="line">D. 使用非阻塞方式下载js脚本，最小化重绘(repaint)和回流(reflow)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>有关JavaScript中系统方法的描述，错误的是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="built_in">parseFloat</span>方法：该方法将一个字符串转换成对应的小数</span><br><span class="line">B. <span class="built_in">isNaN</span>方法：该方法用于检测参数是否为数值型，如果是，返回<span class="literal">true</span>，否则，返回<span class="literal">false</span>。</span><br><span class="line">C. <span class="built_in">escape</span>方法： 该方法返回对一个字符串编码后的结果字符串</span><br><span class="line">D. <span class="built_in">eval</span>方法：该方法将某个参数字符串作为一个<span class="title class_">JavaScript</span>执行题</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面列出的浏览器，无webkit内核的是()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. chrome</span><br><span class="line">B. <span class="title class_">Safari</span></span><br><span class="line">C. 搜狗浏览器</span><br><span class="line">D. <span class="title class_">Firefox</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列代码哪个能够实现获取形式为 2017-08-01 形式的日期( )？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// A</span></span><br><span class="line"><span class="keyword">var</span> formatDate=<span class="title function_">getDate</span>()</span><br><span class="line"><span class="comment">// B</span></span><br><span class="line"><span class="keyword">var</span> formatDate = <span class="keyword">new</span> <span class="title class_">Date</span>()</span><br><span class="line"><span class="comment">// C</span></span><br><span class="line"><span class="keyword">var</span> formatDate = <span class="keyword">function</span> (<span class="params">date</span>) &#123;</span><br><span class="line">    <span class="keyword">var</span> y = date.<span class="title function_">getFullYear</span>();</span><br><span class="line">    <span class="keyword">var</span> m = date.<span class="title function_">getMonth</span>() + <span class="number">1</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">var</span> d = date.<span class="title function_">getDate</span>();</span><br><span class="line">    <span class="keyword">return</span> y + <span class="string">&#x27;-&#x27;</span> + m + <span class="string">&#x27;-&#x27;</span> + d;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">// D</span></span><br><span class="line"><span class="keyword">var</span> formatDate = <span class="keyword">function</span> (<span class="params">date</span>) &#123;</span><br><span class="line">    <span class="keyword">var</span> y = date.<span class="title function_">getFullYear</span>();</span><br><span class="line">    <span class="keyword">var</span> m = date.<span class="title function_">getMonth</span>() + <span class="number">1</span>;</span><br><span class="line">    m = m &lt; <span class="number">10</span> ? <span class="string">&#x27;0&#x27;</span> + m : m;</span><br><span class="line">    <span class="keyword">var</span> d = date.<span class="title function_">getDate</span>();</span><br><span class="line">    d = d &lt; <span class="number">10</span> ? (<span class="string">&#x27;0&#x27;</span> + d) : d;</span><br><span class="line">    <span class="keyword">return</span> y + <span class="string">&#x27;-&#x27;</span> + m + <span class="string">&#x27;-&#x27;</span> + d;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面哪一项不能最小化重绘(repaint)和回流(reflow)</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 需要对元素进行复杂的操作时，可以先隐藏(<span class="attr">display</span>:<span class="string">&quot;none&quot;</span>)，操作完成后再显示</span><br><span class="line">B. 需要创建多个<span class="variable constant_">DOM</span>节点时，使用<span class="title class_">DocumentFragment</span>创建完后一次性的加入<span class="variable language_">document</span></span><br><span class="line">C. 尽量避免用table布局(table元素一旦触发回流就会导致table里所有的其它元素回流)</span><br><span class="line">D. 尽量不要使用 css 属性简写，如：用border-width, border-style, border-color代替border</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">CBBDDD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="JS深入"><a href="#JS深入" class="headerlink" title="JS深入"></a>JS深入</h3><h4 id="this"><a href="#this" class="headerlink" title="this"></a>this</h4><ol>
<li>下列哪种方法不能改变this指向()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="built_in">eval</span></span><br><span class="line">B. apply</span><br><span class="line">C. bind</span><br><span class="line">D. call</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>在JavaScript中下面选项关于this描述正确的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 在使用<span class="keyword">new</span>实例化对象时, <span class="variable language_">this</span>指向这个实例对象</span><br><span class="line">B. 将对象的方法赋值给变量A。执行<span class="title function_">A</span>()时 该方法中的<span class="variable language_">this</span>指向这个对象。 </span><br><span class="line">C. 在函数定义时,<span class="variable language_">this</span>指向全局变量</span><br><span class="line">D. 在浏览器下的全局范围内，<span class="variable language_">this</span>指向全局对象</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面有关JavaScript中call和apply方法的描述，错误的是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. call与apply都属于<span class="title class_">Function</span>.<span class="property"><span class="keyword">prototype</span></span>的一个方法，所以每个<span class="keyword">function</span>实例都有call、apply属性</span><br><span class="line">B. 两者传递的参数不同，call函数第一个参数都是要传入给当前对象的对象，apply不是</span><br><span class="line">C. apply传入的是一个参数数组，也就是将多个参数组合成为一个数组传入</span><br><span class="line">D. call传入的则是直接的参数列表。call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisObj 指定的新对象。</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">AAB</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="作用域-闭包"><a href="#作用域-闭包" class="headerlink" title="作用域(闭包)"></a>作用域(闭包)</h4><ol>
<li>内存泄漏是 javascript 代码中必须尽量避免的，以下几段代码可能会引起内存泄漏的有()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// (1)</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getName</span>(<span class="params"></span>) &#123;</span><br><span class="line">    name = <span class="string">&#x27;javascript&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">getName</span>()</span><br><span class="line"></span><br><span class="line"><span class="comment">// (2)</span></span><br><span class="line"><span class="keyword">const</span> elements = &#123;</span><br><span class="line">    <span class="attr">button</span>: <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;button&#x27;</span>)</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">removeButton</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(elements.<span class="property">button</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">removeButton</span>()</span><br><span class="line"></span><br><span class="line"><span class="comment">// (3)</span></span><br><span class="line"><span class="keyword">let</span> timer = <span class="built_in">setInterval</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> node = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#node&#x27;</span>) </span><br><span class="line">    <span class="keyword">if</span>(node) &#123;</span><br><span class="line">        <span class="built_in">clearInterval</span>(timer)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;, <span class="number">1000</span>);</span><br><span class="line"></span><br><span class="line">A. (<span class="number">1</span>)、(<span class="number">2</span>)、(<span class="number">3</span>)</span><br><span class="line">B. (<span class="number">2</span>)、(<span class="number">3</span>)</span><br><span class="line">C. (<span class="number">1</span>)、(<span class="number">3</span>)</span><br><span class="line">D. (<span class="number">1</span>)、(<span class="number">2</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>那个操作不会造成内存泄露</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 没有清理的<span class="variable constant_">DOM</span>元素引用</span><br><span class="line">B. 被遗忘的定时器</span><br><span class="line">C. 事件侦听没有移除</span><br><span class="line">D. 局部变量不用时，没有设为<span class="literal">null</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列关于闭包理解错误的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 增加一定的内存消耗</span><br><span class="line">B. 使用不当可能会导致内存泄漏</span><br><span class="line">C. 可以使用闭包模拟私有方法</span><br><span class="line">D. 闭包会改动对象的原型链</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">DDD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="原型与继承"><a href="#原型与继承" class="headerlink" title="原型与继承"></a>原型与继承</h4><ol>
<li>JavaScript实现继承的方式，不正确的是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 原型链继承</span><br><span class="line">B. 构造函数继承</span><br><span class="line">C. 组合继承</span><br><span class="line">D. 关联继承</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>所有对象都有原型</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">A. T</span><br><span class="line">B. F</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下关于原型链的描述正确的是:</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 通过原型链继承的属性和对象自己定义的属性等效</span><br><span class="line">B. 通过原型链可以模拟对象的私有属性</span><br><span class="line">C. 在对象上访问不存在的属性时,会依次遍历整条原型链</span><br><span class="line">D. 所有 <span class="title class_">JavaScript</span> 中的对象都是位于原型链顶端的 <span class="string">`Object`</span> 的实例</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">DBC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="其他-1"><a href="#其他-1" class="headerlink" title="其他"></a>其他</h4><ol>
<li>以下不属于前端数据存储方式的是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. jsonp</span><br><span class="line">B. cookie</span><br><span class="line">C. <span class="variable language_">localStorage</span></span><br><span class="line">D. sessionStorage</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">A</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="DOM题"><a href="#DOM题" class="headerlink" title="DOM题"></a>DOM题</h3><h4 id="事件流"><a href="#事件流" class="headerlink" title="事件流"></a>事件流</h4><ol>
<li>将A元素拖拽并放置到B元素中，B元素需要做哪项操作()？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. event.<span class="title function_">preventDefault</span>()</span><br><span class="line">B. event.<span class="title function_">prevent</span>()</span><br><span class="line">C. event.<span class="title function_">drag</span>()</span><br><span class="line">D. event.<span class="title function_">drop</span>()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下不支持冒泡的鼠标事件为(      )？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. mouseover</span><br><span class="line">B. click</span><br><span class="line">C. mouseleave</span><br><span class="line">D. mousemove</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>在javascript中，用于阻止默认事件的默认操作的方法是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title function_">stopDeafault</span>()</span><br><span class="line">B. <span class="title function_">stopPropagation</span>()</span><br><span class="line">C. <span class="title function_">preventDefault</span>()</span><br><span class="line">D. <span class="title function_">preventDefaultEven</span>()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>事件传播的三个阶段是什么</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">目标 -&gt; 捕获 -&gt; 冒泡</span><br><span class="line">冒泡 -&gt; 目标 -&gt; 捕获</span><br><span class="line">目标 -&gt; 冒泡 -&gt; 捕获</span><br><span class="line">捕获 -&gt; 目标 -&gt; 冒泡</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面有关 javascript 常见事件的触发情况，描述错误的是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. onchange：用户改变域的内容</span><br><span class="line">B. onkeypress：某个键盘的键被按下或按住</span><br><span class="line">C. onmousedown：某个鼠标按键被按下</span><br><span class="line">D. onblur：元素获得焦点</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">ACCDD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="DOM遍历"><a href="#DOM遍历" class="headerlink" title="DOM遍历"></a>DOM遍历</h4><ol>
<li>下列哪项不属于DOM查找节点的属性()？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. parentObj.<span class="property">firstChild</span></span><br><span class="line">B. parentObj.<span class="property">children</span></span><br><span class="line">C. neborNode.<span class="property">previousSibling</span></span><br><span class="line">D. neborNode.<span class="property">siblings</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>DOM中，给父节点添加子节点的正确方法为()？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title function_">appendChild</span>(parentNode,newNode);</span><br><span class="line">B. <span class="title function_">append</span>(parentNode,newNode);</span><br><span class="line">C. parentNode.<span class="title function_">append</span>(newNode);</span><br><span class="line">D. parentNode.<span class="title function_">appendChild</span>(newNode);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>JavaScript中document.getElementById()返回值的类型为？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Array</span></span><br><span class="line">B. <span class="title class_">Object</span></span><br><span class="line">C. <span class="title class_">String</span></span><br><span class="line">D. <span class="title class_">Function</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>DOM中，给父节点添加子节点的正确方法为()？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title function_">appendChild</span>(parentNode,newNode);</span><br><span class="line">B. <span class="title function_">append</span>(parentNode,newNode);</span><br><span class="line">C. parentNode.<span class="title function_">append</span>(newNode);</span><br><span class="line">D. parentNode.<span class="title function_">appendChild</span>(newNode);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">DDBD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="其他-2"><a href="#其他-2" class="headerlink" title="其他"></a>其他</h4><ol>
<li>DOM元素的以下属性改变会导致重排(reflows)的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">outline</span><br><span class="line">visiblity</span><br><span class="line">font-size</span><br><span class="line">background-color</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">C</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="BOM题"><a href="#BOM题" class="headerlink" title="BOM题"></a>BOM题</h3><ol>
<li>setInterval(updateClock,60)的含义是(      )？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 每隔<span class="number">60</span>秒调用一次<span class="title function_">updateClock</span>()</span><br><span class="line">B. 每隔<span class="number">60</span>毫秒调用一次<span class="title function_">updateClock</span>()</span><br><span class="line">C. 每隔<span class="number">60</span>分钟调用一次<span class="title function_">updateClock</span>()</span><br><span class="line">D. 每分钟调用<span class="number">60</span>次<span class="title function_">updateClock</span>()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>使用方法(      )可以获取到地理位置所在的经纬度？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Geolocation</span>.<span class="title function_">watchPosition</span>()</span><br><span class="line">B. <span class="title class_">Geolocation</span>.<span class="title function_">getCurrentPosition</span>()</span><br><span class="line">C. <span class="title class_">Geolocation</span>.<span class="title function_">getPosition</span>()</span><br><span class="line">D. <span class="title class_">Geolocation</span>.<span class="title class_">Position</span>()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>setInterval(“alert(‘welcome’);”,1000);这段代码的意思是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 等待<span class="number">1000</span>秒后，再弹出一个对话框</span><br><span class="line">B. 等待<span class="number">1</span>秒钟后弹出一个对话框</span><br><span class="line">C. 每隔一秒钟弹出一个对话框</span><br><span class="line">D. 语句报错,语法有问题</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">BBC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="ES6题"><a href="#ES6题" class="headerlink" title="ES6题"></a>ES6题</h3><h4 id="箭头函数"><a href="#箭头函数" class="headerlink" title="箭头函数"></a>箭头函数</h4><ol>
<li>下列对js箭头函数描述错误的是()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 箭头函数没有原型属性</span><br><span class="line">B. 箭头函数不绑定<span class="variable language_">this</span>，会捕获其所在的上下文的<span class="variable language_">this</span>值，作为自己的<span class="variable language_">this</span>值</span><br><span class="line">C. 箭头函数可以作为构造函数，使用<span class="keyword">new</span></span><br><span class="line">D. 箭头函数不绑定<span class="variable language_">arguments</span>，取而代之用rest参数解决</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>关于箭头函数下列说法错误的一项是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 函数体内<span class="variable language_">this</span>的指向是定义时所在的对象，而不是使用时所在的对象</span><br><span class="line">B. 箭头函数内不能使用<span class="variable language_">arguments</span>对象</span><br><span class="line">C. 箭头函数不能使用<span class="keyword">yield</span>命令</span><br><span class="line">D. 可以使用<span class="keyword">new</span>创建一个箭头函数的实例</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">CD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="promise"><a href="#promise" class="headerlink" title="promise"></a>promise</h4><ol>
<li>关于将 Promise.all 和 Promise.race 传入空数组的两段代码的输出结果说法正确的是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Promise</span>.<span class="title function_">all</span>([]).<span class="title function_">then</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;all&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"><span class="title class_">Promise</span>.<span class="title function_">race</span>([]).<span class="title function_">then</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;race&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">A. all 和 race 都会被输出</span><br><span class="line">B. all 和 race 都不会被输出</span><br><span class="line">C. all 会被输出，而 race 不会被输出</span><br><span class="line">D. all 不会被输出，race 会被输出</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下方案中，不是用于解决回调陷阱的的是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Promise</span></span><br><span class="line">B. <span class="title class_">Generator</span></span><br><span class="line">C. <span class="keyword">async</span></span><br><span class="line">D. <span class="title class_">Proxy</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>在 ECMAScript6 中，不属于promise的状态是:</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Pending</span></span><br><span class="line">B. <span class="title class_">Pause</span></span><br><span class="line">C. <span class="title class_">Fulfilled</span></span><br><span class="line">D. <span class="title class_">Rejected</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">CDB</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="解构赋值"><a href="#解构赋值" class="headerlink" title="解构赋值"></a>解构赋值</h4><ol>
<li>关于ES6解构表达式,描述正确的是()</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> [a,b, c,d, e] = <span class="string">&quot;hello&quot;</span>; </span><br><span class="line"></span><br><span class="line">A. e = <span class="string">&quot;hello&quot;</span>;</span><br><span class="line">B. 其它都为<span class="literal">undefined</span></span><br><span class="line">C. 当中 a = <span class="string">&quot;h&quot;</span>, b = <span class="string">&quot;e&quot;</span>;</span><br><span class="line">D. 语法报错</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">C</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="多选题"><a href="#多选题" class="headerlink" title="多选题"></a>多选题</h2><h3 id="JS基础"><a href="#JS基础" class="headerlink" title="JS基础"></a>JS基础</h3><ol>
<li>下面哪些数组方法会改变原数组</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. push </span><br><span class="line">B. concat </span><br><span class="line">C. splice </span><br><span class="line">D. map</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面可以声明数字的js代码是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="keyword">const</span> a = <span class="number">0xa1</span></span><br><span class="line">B. <span class="keyword">const</span> a = <span class="number">076</span></span><br><span class="line">C. <span class="keyword">const</span> a = 0b21</span><br><span class="line">D. <span class="keyword">const</span> a = <span class="number">7e2</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下属于操作符 typeof 的返回值的是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">(<span class="number">1</span>)<span class="keyword">function</span></span><br><span class="line">(<span class="params"><span class="number">2</span></span>) object</span><br><span class="line">(<span class="number">3</span>) <span class="literal">null</span></span><br><span class="line">(<span class="number">4</span>) array</span><br><span class="line">(<span class="number">5</span>) <span class="title class_">NaN</span></span><br><span class="line">(<span class="number">6</span>) bigint</span><br><span class="line">(<span class="number">7</span>) regexp</span><br><span class="line">(<span class="number">8</span>) <span class="literal">undefined</span></span><br><span class="line"></span><br><span class="line">A. (<span class="number">1</span>)、(<span class="number">2</span>)、(<span class="number">3</span>)、(<span class="number">4</span>)、(<span class="number">5</span>)、(<span class="number">6</span>)、(<span class="number">7</span>)、(<span class="number">8</span>)</span><br><span class="line">B. (<span class="number">1</span>)、(<span class="number">2</span>)、(<span class="number">3</span>)、(<span class="number">8</span>)</span><br><span class="line">C. (<span class="number">1</span>)、(<span class="number">2</span>)、(<span class="number">8</span>)</span><br><span class="line">D. (<span class="number">1</span>)、(<span class="number">2</span>)、(<span class="number">6</span>)、(<span class="number">8</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下()结果等于字符串string</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="keyword">typeof</span> <span class="string">&#x27;string&#x27;</span></span><br><span class="line">B. <span class="title class_">String</span>(<span class="string">&#x27;string&#x27;</span>).<span class="title function_">toString</span>()</span><br><span class="line">C. <span class="string">&#x27;string&#x27;</span>.<span class="title function_">split</span>(<span class="string">&#x27;&#x27;</span>).<span class="title function_">sort</span>().<span class="title function_">join</span>(<span class="string">&#x27;&#x27;</span>)</span><br><span class="line">D. (<span class="keyword">function</span>(<span class="params">string</span>)&#123;<span class="keyword">return</span> string&#125;)(<span class="string">&#x27;string&#x27;</span>)</span><br><span class="line">E. <span class="title class_">JSON</span>.<span class="title function_">parse</span>(<span class="string">&#x27;&#123;&quot;string&quot;:&quot;string&quot;&#125;&#x27;</span>).<span class="property">string</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面的等式成立的是?</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="built_in">parseInt</span>(<span class="number">46.8</span>) <span class="string">`==`</span> <span class="built_in">parseFloat</span>(<span class="number">46.8</span>)</span><br><span class="line">B. <span class="title class_">NaN</span> <span class="string">`!==`</span> <span class="title class_">NaN</span></span><br><span class="line">C. <span class="built_in">isNaN</span>(<span class="string">&#x27;abc&#x27;</span>) <span class="string">`==`</span> <span class="title class_">NaN</span></span><br><span class="line">D. <span class="keyword">typeof</span> <span class="title class_">NaN</span> <span class="string">`===`</span> <span class="string">&#x27;number&#x27;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>以下哪些选项可以将集合A转化为数组？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Array</span>.<span class="title function_">from</span>(A)</span><br><span class="line">B. [].<span class="property">slice</span>.<span class="title function_">apply</span>(A)</span><br><span class="line">C. [...A]</span><br><span class="line">D. [].<span class="property">map</span>.<span class="title function_">call</span>(A, <span class="function"><span class="params">o</span> =&gt;</span> o)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列结果返回 true 的是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="literal">null</span> == <span class="literal">undefined</span></span><br><span class="line">B. <span class="literal">null</span> === <span class="literal">undefined</span></span><br><span class="line">C. <span class="literal">null</span> === <span class="literal">null</span></span><br><span class="line">D. <span class="title class_">NaN</span> == <span class="literal">null</span></span><br><span class="line">E. <span class="title class_">NaN</span> === <span class="title class_">NaN</span></span><br><span class="line">F. <span class="title class_">Infinity</span> + <span class="number">1</span> !== <span class="title class_">Infinity</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">AC</span> <span class="variable constant_">ABD</span> D <span class="variable constant_">ABDE</span> <span class="variable constant_">BD</span> <span class="variable constant_">ABCD</span> <span class="variable constant_">AC</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="JS深入-1"><a href="#JS深入-1" class="headerlink" title="JS深入"></a>JS深入</h3><ol>
<li>关于以下代码，说法正确的有哪些？</li>
</ol>
<p>function Person() { } var person &#x3D; new Person();</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. 每一个原型都有一个constructor属性指向关联的构造函数。</span><br><span class="line">B. 每一个对象都有一个prototype属性。</span><br><span class="line">C. <span class="title class_">Object</span>.<span class="title function_">getPrototypeOf</span>(person) === <span class="title class_">Person</span>.<span class="property"><span class="keyword">prototype</span></span></span><br><span class="line">D. person.<span class="property">constructor</span> === <span class="title class_">Person</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列在 JS 时间循环机制中属于微任务(microTask)的是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. process.<span class="property">nextTick</span></span><br><span class="line">B. promise</span><br><span class="line">C. <span class="built_in">setTimeout</span></span><br><span class="line">D. <span class="built_in">setInterval</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">ACD</span> <span class="variable constant_">AB</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="ES6"><a href="#ES6" class="headerlink" title="ES6"></a>ES6</h3><ol>
<li>以下关于let和const的说法中正确的是:</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="keyword">let</span>声明的变量值和类型都可以改变</span><br><span class="line">B. <span class="keyword">const</span>声明的常量不可以改变</span><br><span class="line">C. 两者都不存在变量提升，同时存在暂时性死区，只能在声明的位置后面使用</span><br><span class="line">D. <span class="keyword">const</span>可以先声明再初始化，可以后赋值</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面关于Promise说法正确的是(注意“返回结果”的意思包含成功或者失败)</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. <span class="title class_">Promise</span>.<span class="property">all</span>在所有给定的promise都fulfilled后才返回结果</span><br><span class="line">B. <span class="title class_">Promise</span>.<span class="property">race</span>在给定的promise中，某个fulfilled后才返回结果</span><br><span class="line">C. promise.<span class="property">then</span>的回调函数中，可以返回一个新的promise</span><br><span class="line">D. 对于一个向后台获取数据已经产生结果的<span class="attr">promise</span>:p1，再次调用p1.<span class="property">then</span>，不会去重新发起请求获取数据</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">ABC</span> <span class="variable constant_">CD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="DOM"><a href="#DOM" class="headerlink" title="DOM"></a>DOM</h3><ol>
<li>下列关于使用 JS 修改元素样式的代码，正确的有哪些？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">document</span>.<span class="property">body</span>.<span class="property">style</span>.[<span class="string">&#x27;background-color&#x27;</span>] = <span class="string">&#x27;#fff&#x27;</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="property">body</span>.<span class="property">style</span>.<span class="title function_">setProperty</span>(<span class="string">&#x27;background-color&#x27;</span>, <span class="string">&#x27;#fff&#x27;</span>)</span><br><span class="line"><span class="variable language_">document</span>.<span class="property">body</span>.<span class="property">style</span> = <span class="string">&#x27;background-color&#x27;</span>: #fff<span class="string">&#x27;</span></span><br><span class="line"><span class="string">document.body.style.fontSize = &#x27;</span>14px<span class="string">&#x27;</span></span><br><span class="line"><span class="string"></span></span><br></pre></td></tr></table></figure>

<ol>
<li>下列方法可用于阻止事件冒泡的有</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">A. event.<span class="property">cancelBubble</span> = <span class="literal">true</span>;</span><br><span class="line">B. event.<span class="title function_">stopPropagation</span>();</span><br><span class="line">C. event.<span class="title function_">preventDefault</span>();</span><br><span class="line">D. <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>答案</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable constant_">BCD</span> <span class="variable constant_">ABD</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="填空题"><a href="#填空题" class="headerlink" title="填空题"></a>填空题</h2><h3 id="类型检测"><a href="#类型检测" class="headerlink" title="类型检测"></a>类型检测</h3><ol>
<li>在JavaScript中，有var arr &#x3D; []; typeof arr的结果为</li>
<li>以下使用 typeof 操作符的代码的输出结果为</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> x = <span class="keyword">typeof</span> x</span><br><span class="line"><span class="keyword">var</span> res = <span class="keyword">typeof</span> <span class="keyword">typeof</span> x;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(x, res)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>[typeof null, null instanceof Object]的结果是什么</li>
<li>typeof typeof 0</li>
<li>JavaScript的typeof运算符的可能结果为array？解释为什么</li>
<li>下面代码的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [];</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="keyword">typeof</span> arr, <span class="title class_">Object</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">toString</span>.<span class="title function_">call</span>(arr));</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>console.log(Object.prototype.toString.call(undefined))</li>
</ol>
<h4 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h4><ol>
<li>表达式 “2”+3+4 的值为</li>
<li>console.log(‘5’ + 3, 5 + ‘3’)</li>
<li>var a&#x3D;parseInt(“111办公室”);alert(a);</li>
<li>[“0x1”, “0x2”, “0x3”].map(parseInt) 的结果</li>
<li>在js中执行 1+’1’的结果是？</li>
<li>在js中执行 parseInt(‘77’,40)的结果是?</li>
</ol>
<h4 id="逻辑判断-1"><a href="#逻辑判断-1" class="headerlink" title="逻辑判断"></a>逻辑判断</h4><ol>
<li>请给出 [5&lt;6&lt;3,3&lt;2&lt;4] 代码的运行结果</li>
<li>(2&lt;3)||(3&lt;2) 表达式将返回值为</li>
<li>console.log(true||false&amp;&amp;false, true&amp;&amp;false||true)的输出结果是？</li>
</ol>
<h3 id="其他-3"><a href="#其他-3" class="headerlink" title="其他"></a>其他</h3><ol>
<li>1 + - + + + - + 1 的结果是</li>
<li>[ ‘a’, ,’b’, ,].length 的结果是</li>
</ol>
<h2 id="程序题"><a href="#程序题" class="headerlink" title="程序题"></a>程序题</h2><h3 id="JS基础-1"><a href="#JS基础-1" class="headerlink" title="JS基础"></a>JS基础</h3><ol>
<li>下面两个程序的输出结果分别是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// case 1</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">showCase</span>(<span class="params">value</span>) &#123;</span><br><span class="line">    <span class="keyword">switch</span>(value) &#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;A&#x27;</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case A&#x27;</span>);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;B&#x27;</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case B&#x27;</span>);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="attr">undefined</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case undefined&#x27;</span>);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="attr">default</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case default&#x27;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">showCase</span>(<span class="keyword">new</span> <span class="title class_">String</span>(<span class="string">&#x27;A&#x27;</span>));</span><br><span class="line"></span><br><span class="line"><span class="comment">// case 2</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">showCase</span>(<span class="params">value</span>) &#123;</span><br><span class="line">    <span class="keyword">switch</span>(value) &#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;A&#x27;</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case A&#x27;</span>);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;B&#x27;</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case B&#x27;</span>);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">case</span> <span class="attr">undefined</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case undefined&#x27;</span>);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="attr">default</span>:</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Case default&#x27;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">showCase</span>(<span class="title class_">String</span>(<span class="string">&#x27;A&#x27;</span>));</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>p标签的的内容会显示什么？</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span> <span class="attr">id</span>=<span class="string">&quot;demo&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> x = <span class="number">10</span>;</span></span><br><span class="line"><span class="language-javascript">            <span class="keyword">var</span> y = <span class="string">&quot;10&quot;</span>;</span></span><br><span class="line"><span class="language-javascript">            <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;demo&quot;</span>).<span class="property">innerHTML</span> = <span class="title class_">Boolean</span>(x == y);</span></span><br><span class="line"><span class="language-javascript">        </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>document.write的结果会是什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">funcA</span>(<span class="params">x</span>)&#123;</span><br><span class="line">    <span class="keyword">var</span> temp = <span class="number">4</span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">funcB</span>(<span class="params">y</span>)&#123;</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">write</span>( ++x + y + (temp--));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="title function_">funcB</span>(<span class="number">5</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="title function_">funcA</span>(<span class="number">6</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>alert的结果会是多少</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> varArr = <span class="keyword">function</span>(<span class="params">i,j,str</span>) &#123;  </span><br><span class="line">    <span class="keyword">return</span> j == <span class="number">0</span> ? str : <span class="title function_">varArr</span>(i,--j,(str+= <span class="string">&quot; &quot;</span> + i[j]));</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="title class_">Array</span>(<span class="string">&#x27;apple&#x27;</span>,<span class="string">&#x27;orange&#x27;</span>,<span class="string">&#x27;peach&#x27;</span>,<span class="string">&#x27;lime&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> str = <span class="title function_">varArr</span>(arr,arr.<span class="property">length</span>,<span class="string">&quot;&quot;</span>);</span><br><span class="line"><span class="title function_">alert</span>(str);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">greetingMaker</span>(<span class="params">greeting</span>) &#123; </span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">addName</span>(<span class="params">name</span>) &#123;    </span><br><span class="line">        greeting  = greeting.<span class="title function_">split</span>(<span class="string">&#x27; &#x27;</span>).<span class="title function_">reverse</span>().<span class="title function_">join</span>(<span class="string">&quot;-&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> greeting + <span class="string">&quot; &quot;</span> + name;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> addName;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> daytimeGreeting = <span class="title function_">greetingMaker</span>(<span class="string">&quot;Good Day to you&quot;</span>);</span><br><span class="line"><span class="title function_">alert</span>(<span class="title function_">daytimeGreeting</span>(name)); </span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">String</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">GetNum</span> = <span class="keyword">function</span>(<span class="params"></span>) &#123; </span><br><span class="line">    <span class="keyword">var</span> regEx = <span class="regexp">/[^\d]/g</span>; </span><br><span class="line">    <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="title function_">replace</span>(regEx, <span class="string">&#x27;&#x27;</span>); </span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">&quot;a1b2c3&quot;</span>;</span><br><span class="line">str = str.<span class="title class_">GetNum</span>();</span><br><span class="line"><span class="title function_">alert</span>(str);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">sum</span>(<span class="params">a, b</span>) &#123;</span><br><span class="line">  <span class="keyword">return</span> a + b;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">sum</span>(<span class="number">1</span>, <span class="string">&quot;2&quot;</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&quot;我非常喜欢编程&quot;</span>;</span><br><span class="line">str.<span class="property">length</span> = <span class="number">3</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(str);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> number = <span class="number">0</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(number++);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(++number);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(number);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">nums</span>(<span class="params">a, b</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (a &gt; b)</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;a is bigger&#x27;</span>)</span><br><span class="line">    <span class="keyword">else</span> </span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;b is bigger&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> a + b</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">nums</span>(<span class="number">4</span>, <span class="number">2</span>))</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">nums</span>(<span class="number">1</span>, <span class="number">2</span>))</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">side</span>(<span class="params">arr</span>) &#123;</span><br><span class="line">    arr[<span class="number">0</span>] = arr[<span class="number">2</span>];</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">func1</span>(<span class="params">a, b, c = <span class="number">3</span></span>) &#123;</span><br><span class="line">    c = <span class="number">10</span>;</span><br><span class="line">    <span class="title function_">side</span>(<span class="variable language_">arguments</span>);</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(a + b + c);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">func2</span>(<span class="params">a, b, c</span>) &#123;</span><br><span class="line">    c = <span class="number">10</span>;</span><br><span class="line">    <span class="title function_">side</span>(<span class="variable language_">arguments</span>);</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(a + b + c);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">func1</span>(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line"><span class="title function_">func2</span>(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面代码的输出结果是什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">3</span>;</span><br><span class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> <span class="title class_">Number</span>(<span class="number">3</span>);</span><br><span class="line"><span class="keyword">var</span> c = <span class="number">3</span>;</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a == b);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a === b);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(b === c);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>执行下列语句后，a.length的值为？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = [];</span><br><span class="line">a.<span class="title function_">push</span>(<span class="number">1</span>, <span class="number">2</span>);</span><br><span class="line">a.<span class="title function_">shift</span>(<span class="number">3</span>, <span class="number">4</span>);</span><br><span class="line">a.<span class="title function_">concat</span>([<span class="number">5</span>, <span class="number">6</span>]);</span><br><span class="line">a.<span class="title function_">splice</span>(<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面这几段代码分别输出结果是多少？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = &#123;&#125;, b = <span class="string">&#x27;123&#x27;</span>, c = <span class="number">123</span>;</span><br><span class="line">a[b] = <span class="string">&#x27;b&#x27;</span>;</span><br><span class="line">a[c] = <span class="string">&#x27;c&#x27;</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a[b]);</span><br><span class="line"><span class="comment">// example 2</span></span><br><span class="line"><span class="keyword">var</span> a = &#123;&#125;, b = <span class="title class_">Symbol</span>(<span class="string">&#x27;123&#x27;</span>), c = <span class="title class_">Symbol</span>(<span class="string">&#x27;123&#x27;</span>);</span><br><span class="line">a[b] = <span class="string">&#x27;b&#x27;</span>;</span><br><span class="line">a[c] = <span class="string">&#x27;c&#x27;</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a[b]);</span><br><span class="line"><span class="comment">// example 3</span></span><br><span class="line"><span class="keyword">var</span> a = &#123;&#125;, b = &#123;<span class="attr">key</span>:<span class="string">&#x27;123&#x27;</span>&#125;, c = &#123;<span class="attr">key</span>:<span class="string">&#x27;456&#x27;</span>&#125;;</span><br><span class="line">a[b] = <span class="string">&#x27;b&#x27;</span>;</span><br><span class="line">a[c] = <span class="string">&#x27;c&#x27;</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a[b]);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面每项的返回值是什么？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="literal">null</span> == <span class="literal">undefined</span></span><br><span class="line"><span class="number">0.1</span> + <span class="number">0.2</span> == <span class="number">0.3</span></span><br><span class="line"><span class="keyword">typeof</span> <span class="title class_">NaN</span></span><br><span class="line"><span class="keyword">typeof</span> <span class="title class_">Function</span></span><br><span class="line"><span class="keyword">typeof</span> <span class="title class_">Object</span></span><br><span class="line"><span class="keyword">typeof</span> &#123;&#125;</span><br><span class="line"><span class="string">&#x27;a&#x27;</span> + <span class="number">1</span></span><br><span class="line"><span class="string">&#x27;a&#x27;</span> - <span class="number">1</span></span><br><span class="line"><span class="title class_">Function</span> <span class="keyword">instanceof</span> <span class="title class_">Object</span></span><br><span class="line"><span class="title class_">Object</span> <span class="keyword">instanceof</span> <span class="title class_">Function</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> array = []</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++) &#123;</span><br><span class="line">    array.<span class="title function_">push</span>(<span class="function">() =&gt;</span> i)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> newArray = array.<span class="title function_">map</span>(<span class="function"><span class="params">el</span> =&gt;</span> <span class="title function_">el</span>())</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(newArray)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"> <span class="keyword">function</span> <span class="title function_">a</span>(<span class="params">m, n</span>) &#123;</span><br><span class="line">        <span class="keyword">var</span> b = <span class="keyword">function</span> (<span class="params">l</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> l &lt;= m ? l * <span class="title function_">b</span>(l + <span class="number">1</span>) : <span class="number">1</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> <span class="title function_">b</span>(m - n + <span class="number">1</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">a</span>(<span class="number">4</span>, <span class="number">2</span>));</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="keyword">typeof</span> <span class="literal">undefined</span> == <span class="keyword">typeof</span> <span class="variable constant_">NULL</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="keyword">typeof</span> <span class="keyword">function</span> (<span class="params"></span>) &#123;&#125; == <span class="keyword">typeof</span> <span class="keyword">class</span> &#123;&#125;);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>执行后a和b.age的值分别为</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">10</span></span><br><span class="line"><span class="keyword">var</span> b = &#123;</span><br><span class="line">    <span class="attr">age</span>: <span class="number">11</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">fn</span>(<span class="params">x,y</span>) &#123;</span><br><span class="line">    --y.<span class="property">age</span>;</span><br><span class="line">    <span class="keyword">return</span> --x;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">fn</span>(a,b)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的执行结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> number = <span class="number">4</span>;</span><br><span class="line"><span class="keyword">var</span> numberFactorial = (<span class="keyword">function</span> (<span class="params">number</span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> (number === <span class="number">0</span>)? <span class="number">1</span>: number* <span class="title function_">factorial</span>(number-<span class="number">1</span>)</span><br><span class="line">&#125;)(number)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(numberFactorial)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> array = []</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++) &#123;</span><br><span class="line">    array.<span class="title function_">push</span>(<span class="function">() =&gt;</span> i)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> newArray = array.<span class="title function_">map</span>(<span class="function"><span class="params">el</span> =&gt;</span> <span class="title function_">el</span>())</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(newArray)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">addToList</span>(<span class="params">item, list</span>) &#123;</span><br><span class="line">    <span class="keyword">return</span> list.<span class="title function_">push</span>(item)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">const</span> result = <span class="title function_">addToList</span>(<span class="string">&quot;nowcoder&quot;</span>, [<span class="string">&quot;hello&quot;</span>])</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title function_">first</span> = (<span class="params"></span>) =&gt; &#123; <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;first&#x27;</span>); <span class="keyword">return</span> <span class="literal">false</span>; &#125;</span><br><span class="line"><span class="keyword">const</span> <span class="title function_">second</span> = (<span class="params"></span>) =&gt; &#123; <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;second&#x27;</span>); <span class="keyword">return</span> <span class="literal">true</span>; &#125;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>( <span class="title function_">first</span>() &amp;&amp; <span class="title function_">second</span>() );</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>( <span class="title function_">second</span>() || <span class="title function_">first</span>() );</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面代码的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> s=<span class="string">&#x27;12ab3cd&#x27;</span>, arr=s.<span class="title function_">split</span>(<span class="regexp">/\d/</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(arr[<span class="number">3</span>],arr[<span class="number">4</span>])</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">getAge</span>(<span class="params">...args</span>) &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="keyword">typeof</span> args);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="title function_">getAge</span>(<span class="number">21</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是:</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr=[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line">arr.<span class="title function_">push</span>(arr.<span class="title function_">shift</span>())</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(arr[<span class="number">1</span>],arr[<span class="number">2</span>])</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="JS深入-2"><a href="#JS深入-2" class="headerlink" title="JS深入"></a>JS深入</h3><h4 id="this指向"><a href="#this指向" class="headerlink" title="this指向"></a>this指向</h4><p>题目解析：<a target="_blank" rel="noopener" href="https://juejin.cn/post/7023944134561890318">this指向题目解析及扩展</a></p>
<ol>
<li>下列程序的输出结果是多少？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> x = <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">    <span class="attr">x</span>: <span class="number">3</span>,</span><br><span class="line">    <span class="attr">fun</span>:<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">        <span class="keyword">var</span> x = <span class="number">5</span>;</span><br><span class="line">        <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">x</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> fun = obj.<span class="property">fun</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>( obj.<span class="title function_">fun</span>(), <span class="title function_">fun</span>() );</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列程序的输出结果是多少？你能理清楚test函数的this指向吗？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">5</span>;</span><br><span class="line"> <span class="keyword">function</span> <span class="title function_">test</span>(<span class="params"></span>) &#123; </span><br><span class="line">    a = <span class="number">0</span>; </span><br><span class="line">    <span class="title function_">alert</span>(a); </span><br><span class="line">    <span class="title function_">alert</span>(<span class="variable language_">this</span>.<span class="property">a</span>); </span><br><span class="line">    <span class="keyword">var</span> a;</span><br><span class="line">    <span class="title function_">alert</span>(a); </span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">new</span> <span class="title function_">test</span>();</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下列程序的输出结果是多少？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">fun</span> () &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="function">() =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="function">() =&gt;</span> &#123;</span><br><span class="line">                <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">name</span>)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> f = fun.<span class="title function_">call</span>(&#123;<span class="attr">name</span>: <span class="string">&#x27;foo&#x27;</span>&#125;)</span><br><span class="line"><span class="keyword">var</span> t1 = f.<span class="title function_">call</span>(&#123;<span class="attr">name</span>: <span class="string">&#x27;bar&#x27;</span>&#125;)()()</span><br><span class="line"><span class="keyword">var</span> t2 = <span class="title function_">f</span>().<span class="title function_">call</span>(&#123;<span class="attr">name</span>: <span class="string">&#x27;baz&#x27;</span>&#125;)()</span><br><span class="line"><span class="keyword">var</span> t3 = <span class="title function_">f</span>()().<span class="title function_">call</span>(&#123;<span class="attr">name</span>: <span class="string">&#x27;qux&#x27;</span>&#125;)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>执行以下代码，输出结果分别是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> obj1 = &#123;</span><br><span class="line">    <span class="attr">a</span>: <span class="number">1</span>,</span><br><span class="line">    <span class="attr">foo</span>: <span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">a</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// log1</span></span><br><span class="line">obj1.<span class="title function_">foo</span>()</span><br><span class="line"><span class="keyword">const</span> obj2 = obj1.<span class="property">foo</span></span><br><span class="line"><span class="comment">// log2</span></span><br><span class="line"><span class="title function_">obj2</span>()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是什么？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title function_">Person</span> = (<span class="params">name=<span class="string">&quot;wang&quot;</span>,age=<span class="number">10</span></span>) =&gt; &#123;</span><br><span class="line"><span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line"><span class="variable language_">this</span>.<span class="property">age</span> = age;</span><br><span class="line"><span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">name</span> +<span class="string">&#x27; is &#x27;</span>+ <span class="variable language_">this</span>.<span class="property">age</span> + <span class="string">&#x27;years old&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">let</span> result = <span class="keyword">new</span> <span class="title class_">Person</span>(<span class="string">&#x27;zhang&#x27;</span>,<span class="number">11</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请表述以下代码的执行结果和原因</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> person = &#123;</span><br><span class="line">  <span class="attr">age</span>: <span class="number">18</span>,</span><br><span class="line">  <span class="attr">getAge</span>: <span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">age</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">var</span> getAge = person.<span class="property">getAge</span></span><br><span class="line"><span class="title function_">getAge</span>()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请按顺序写出打印结果，并说明原因。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">&#x27;global&#x27;</span>;</span><br><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">    <span class="attr">name</span>: <span class="string">&#x27;local&#x27;</span>,</span><br><span class="line">    <span class="attr">foo</span>: <span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">        <span class="variable language_">this</span>.<span class="property">name</span> = <span class="string">&#x27;foo&#x27;</span>;</span><br><span class="line">    &#125;.<span class="title function_">bind</span>(<span class="variable language_">window</span>)</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">var</span> bar = <span class="keyword">new</span> obj.<span class="title function_">foo</span>();</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">window</span>.<span class="property">name</span>);</span><br><span class="line">&#125;, <span class="number">0</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(bar.<span class="property">name</span>);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">var</span> bar3 = bar2 = bar;</span><br><span class="line">bar2.<span class="property">name</span> = <span class="string">&#x27;foo2&#x27;</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(bar3.<span class="property">name</span>);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的执行结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">    <span class="attr">name</span>:<span class="string">&quot;zhangsan&quot;</span>,</span><br><span class="line">    <span class="attr">sayName</span>:<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="variable language_">this</span>.<span class="property">name</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> wfunc = obj.<span class="property">sayName</span>;</span><br><span class="line">obj.<span class="title function_">sayName</span>();</span><br><span class="line"><span class="title function_">wfunc</span>();</span><br><span class="line"><span class="keyword">var</span> name = <span class="string">&quot;lisi&quot;</span>;</span><br><span class="line">obj.<span class="title function_">sayName</span>();</span><br><span class="line"><span class="title function_">wfunc</span>();</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name=<span class="string">&#x27;test&#x27;</span> </span><br><span class="line"><span class="keyword">var</span> a = &#123;    </span><br><span class="line">    <span class="attr">name</span>: <span class="string">&#x27;ass&#x27;</span>,    </span><br><span class="line">    <span class="attr">getName</span>: <span class="keyword">function</span>(<span class="params"></span>) &#123;    </span><br><span class="line">        <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">name</span>;   </span><br><span class="line">    &#125; </span><br><span class="line">&#125; </span><br><span class="line"><span class="keyword">var</span> b = a.<span class="property">getName</span>; </span><br><span class="line"><span class="title function_">b</span>();</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="事件循环"><a href="#事件循环" class="headerlink" title="事件循环"></a>事件循环</h4><ol>
<li>下列程序的输出结果分别是多少？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> promiseA = <span class="title class_">Promise</span>.<span class="title function_">resolve</span>(<span class="string">&#x27;a&#x27;</span>)</span><br><span class="line">promiseA. <span class="title function_">then</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(res)</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(res)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">const</span> promiseB = <span class="title class_">Promise</span>.<span class="title function_">resolve</span>(<span class="string">&#x27;b&#x27;</span>)</span><br><span class="line">promiseB. <span class="title function_">then</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(res)</span><br><span class="line">&#125;)</span><br><span class="line">promiseB. <span class="title function_">then</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(res)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果依次是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>)</span><br><span class="line">&#125;, <span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> P = <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>)</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="title function_">resolve</span>()</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">3</span>)</span><br><span class="line">    &#125;, <span class="number">0</span>)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">P.<span class="title function_">then</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">4</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">5</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>);</span><br><span class="line">&#125;, <span class="number">0</span>)</span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="keyword">function</span>(<span class="params">resolve</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>);</span><br><span class="line">    <span class="title function_">resolve</span>();</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">3</span>);</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">4</span>);</span><br><span class="line">&#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">5</span>);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">(<span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>);</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>);</span><br><span class="line">&#125;, <span class="number">0</span>);</span><br><span class="line"><span class="keyword">await</span> <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">3</span>);</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">4</span>);</span><br><span class="line">&#125;);</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">5</span>);</span><br><span class="line">&#125;)();</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是:</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;1&#x27;</span>)</span><br><span class="line">    <span class="title function_">resolve</span>()</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;2&#x27;</span>)</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;3&#x27;</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;4&#x27;</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;5&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是:</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> p1 = <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="keyword">function</span>(<span class="params">resolve, reject</span>)&#123;</span><br><span class="line">    <span class="title function_">resolve</span>(<span class="string">&quot;2&quot;</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;1&quot;</span>)</span><br><span class="line">&#125;,<span class="number">10</span>)</span><br><span class="line">p1.<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params">value</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(value)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;3&quot;</span>)</span><br><span class="line">&#125;,<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;setTimeout&#x27;</span>);</span><br><span class="line">&#125;, <span class="number">0</span>);</span><br><span class="line"><span class="title class_">Promise</span>.<span class="title function_">resolve</span>().<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;promise1&#x27;</span>);</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;promise2&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请表述以下代码的执行结果和原因</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>)</span><br><span class="line">&#125;,<span class="number">0</span>)</span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="keyword">function</span> <span class="title function_">executor</span>(<span class="params">resolve</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>)</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i&lt;<span class="number">10000</span>; i++) &#123;</span><br><span class="line">        i - <span class="number">9999</span> &amp;&amp; <span class="title function_">resolve</span>()</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">3</span>)</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">4</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">5</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>在网页中有两个div块，html代码如下</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;outer&quot;</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;inner&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>对应的js代码如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> outer = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.outer&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> inner = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.inner&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">onClick</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;click&#x27;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;timeout&#x27;</span>);</span><br><span class="line">    &#125;, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">    <span class="title class_">Promise</span>.<span class="title function_">resolve</span>().<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;promise&#x27;</span>);</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    outer.<span class="title function_">setAttribute</span>(<span class="string">&#x27;data-random&#x27;</span>, <span class="title class_">Math</span>.<span class="title function_">random</span>());</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">inner.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, onClick);</span><br><span class="line">outer.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, onClick);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>当点击class为inner的div块时，控制台依次输出结果是什么？ 10. 下面程序的输出结果是？</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">(<span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>);</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>);</span><br><span class="line">&#125;, <span class="number">0</span>);</span><br><span class="line"><span class="keyword">await</span> <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">3</span>);</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">4</span>);</span><br><span class="line">&#125;);</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">5</span>);</span><br><span class="line">&#125;)();</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;a&#x27;</span>));</span><br><span class="line"><span class="title class_">Promise</span>.<span class="title function_">resolve</span>().<span class="title function_">then</span>(</span><br><span class="line">   <span class="function">() =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;b’);</span></span><br><span class="line"><span class="string"> ).then(</span></span><br><span class="line"><span class="string">   () =&gt; Promise.resolve(&#x27;</span>c<span class="string">&#x27;).then(</span></span><br><span class="line"><span class="string">     (data) =&gt; &#123;</span></span><br><span class="line"><span class="string">       setTimeout(() =&gt; console.log(&#x27;</span>d<span class="string">&#x27;));</span></span><br><span class="line"><span class="string">       console.log(&#x27;</span>f<span class="string">&#x27;);</span></span><br><span class="line"><span class="string">       return data;</span></span><br><span class="line"><span class="string">     &#125;</span></span><br><span class="line"><span class="string">   )</span></span><br><span class="line"><span class="string"> ).then(data =&gt; console.log(data));</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"></span></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;one&#x27;</span>); </span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123; <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;two&#x27;</span>); &#125;, <span class="number">0</span>); </span><br><span class="line"><span class="title class_">Promise</span>.<span class="title function_">resolve</span>()</span><br><span class="line">       .<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123; <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;three&#x27;</span>); &#125;)</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;four&#x27;</span>);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的执行结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(C)</span><br><span class="line">&#125;,<span class="number">0</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;D&#x27;</span>)</span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="keyword">function</span>(<span class="params">resolve</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;E&#x27;</span>)</span><br><span class="line">    <span class="title function_">resolve</span>()</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;F&#x27;</span>)</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;G&#x27;</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;H&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>有一个输出函数定义如下：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">log</span>(<span class="params">msg, time</span>) &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(msg);</span><br><span class="line">      <span class="title function_">resolve</span>();</span><br><span class="line">    &#125;, time);</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>则下面三段代码输出的结果是：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一段代码：</span></span><br><span class="line">(<span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;</span><br><span class="line">    <span class="keyword">await</span> <span class="title function_">log</span>(i, <span class="number">1000</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 第二段代码：</span></span><br><span class="line">(<span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">  [ <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span> ].<span class="title function_">forEach</span>(<span class="keyword">async</span> (i) =&gt; &#123;</span><br><span class="line">    <span class="keyword">await</span> <span class="title function_">log</span>(i, <span class="number">1000</span>);</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;)();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 第三段代码：</span></span><br><span class="line">(<span class="keyword">async</span> () =&gt; &#123;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">const</span> i <span class="keyword">of</span> [ <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span> ]) &#123;</span><br><span class="line">    <span class="keyword">await</span> <span class="title function_">log</span>(i, <span class="number">1000</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)();</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="原型与原型链"><a href="#原型与原型链" class="headerlink" title="原型与原型链"></a>原型与原型链</h4><p>传送门: <a target="_blank" rel="noopener" href="https://juejin.cn/post/7025939091560611848">原型与原型链题目解析</a></p>
<ol>
<li>下面程序的输出结果依次是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">Fn1</span>(<span class="params">name</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span>(name)&#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title class_">Fn1</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">name</span>=<span class="string">&quot;jack&quot;</span></span><br><span class="line"><span class="keyword">let</span> a = <span class="keyword">new</span> <span class="title class_">Fn1</span>();</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;a:&#x27;</span>, a.<span class="property">name</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">Fn2</span>(<span class="params">name</span>) &#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title class_">Fn2</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">name</span>=<span class="string">&quot;jack&quot;</span></span><br><span class="line"><span class="keyword">let</span> b = <span class="keyword">new</span> <span class="title class_">Fn2</span>();</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;b:&#x27;</span>, b.<span class="property">name</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> <span class="title class_">Foo</span> = (<span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="keyword">var</span> x = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">Foo</span>(<span class="params"></span>) &#123;&#125;</span><br><span class="line">    <span class="title class_">Foo</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">increment</span> = <span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">        ++x;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(x);</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="keyword">return</span> <span class="title class_">Foo</span>;</span><br><span class="line">&#125;)();</span><br><span class="line"> </span><br><span class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="title class_">Foo</span>();</span><br><span class="line">a.<span class="title function_">increment</span>();</span><br><span class="line">a.<span class="title function_">increment</span>();</span><br><span class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> <span class="title class_">Foo</span>();</span><br><span class="line">a.<span class="title function_">increment</span>();</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">&#x27;Jay&#x27;</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">Person</span>(<span class="params">name</span>)&#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">name</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> a = <span class="title class_">Person</span>(<span class="string">&#x27;Tom&#x27;</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(name)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a)</span><br><span class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> <span class="title class_">Person</span>(<span class="string">&#x27;Michael&#x27;</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(b)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请表述以下代码的执行结果和原因</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">A</span>&#123;&#125;</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">B</span> <span class="keyword">extends</span> <span class="title class_ inherited__">A</span>&#123;&#125;</span><br><span class="line"><span class="keyword">const</span> a = <span class="keyword">new</span> <span class="title function_">A</span>()</span><br><span class="line"><span class="keyword">const</span> b = <span class="keyword">new</span> <span class="title function_">B</span>()</span><br><span class="line">a.<span class="property">__proto__</span></span><br><span class="line">b.<span class="property">__proto__</span></span><br><span class="line">B. __proto__</span><br><span class="line">B. prototype.<span class="property">__proto__</span></span><br><span class="line">b.<span class="property">__proto__</span>.<span class="property">__proto__</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请表述以下代码的执行结果和原因</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">test</span>(<span class="params"></span>) &#123;           </span><br><span class="line">    getName = <span class="keyword">function</span>(<span class="params"></span>) &#123; </span><br><span class="line">        <span class="title class_">Promise</span>.<span class="title function_">resolve</span>().<span class="title function_">then</span>(<span class="function">() =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">0</span>)); </span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>);               </span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="variable language_">this</span>; </span><br><span class="line">&#125;</span><br><span class="line">test.<span class="property">getName</span> = <span class="keyword">function</span>(<span class="params"></span>) &#123; </span><br><span class="line">     <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>), <span class="number">0</span>); </span><br><span class="line">     <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">3</span>);               </span><br><span class="line">&#125;;</span><br><span class="line">test.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">getName</span> = <span class="keyword">function</span>(<span class="params"></span>) &#123;    </span><br><span class="line"></span><br><span class="line">     <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">4</span>); </span><br><span class="line">&#125;;       </span><br><span class="line"><span class="keyword">var</span> getName = <span class="keyword">function</span>(<span class="params"></span>) &#123; </span><br><span class="line">     <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">5</span>);             </span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getName</span>(<span class="params"></span>) &#123;</span><br><span class="line"></span><br><span class="line">     <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">6</span>); </span><br><span class="line">&#125;      </span><br><span class="line">      </span><br><span class="line">test.<span class="title function_">getName</span>(); </span><br><span class="line"><span class="title function_">getName</span>(); </span><br><span class="line"><span class="title function_">test</span>().<span class="title function_">getName</span>(); </span><br><span class="line"><span class="title function_">getName</span>();  </span><br><span class="line"><span class="keyword">new</span> test.<span class="title function_">getName</span>();</span><br><span class="line"><span class="keyword">new</span> <span class="title function_">test</span>().<span class="title function_">getName</span>();</span><br><span class="line"><span class="keyword">new</span> <span class="keyword">new</span> <span class="title function_">test</span>().<span class="title function_">getName</span>();</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请表述以下代码的执行结果和原因</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> tmp = &#123;&#125;;</span><br><span class="line"><span class="keyword">var</span> A = <span class="keyword">function</span>(<span class="params"></span>) &#123;&#125;;</span><br><span class="line">A. prototype = tmp;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="title function_">A</span>();</span><br><span class="line">A. prototype = &#123;&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> b = <span class="title class_">Object</span>.<span class="title function_">create</span>(tmp);</span><br><span class="line">b.<span class="property">constructor</span> = A. constructor;</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a <span class="keyword">instanceof</span> A);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(b <span class="keyword">instanceof</span> A);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的执行结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">Foo</span>(<span class="params"></span>)&#123;&#125;</span><br><span class="line"><span class="title class_">Foo</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">z</span> = <span class="number">3</span>;</span><br><span class="line"><span class="keyword">var</span> obj = <span class="keyword">new</span> <span class="title class_">Foo</span>();</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">info</span>(obj.<span class="property">z</span>)</span><br><span class="line">obj.<span class="property">z</span> = <span class="number">10</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">info</span>(obj.<span class="property">z</span>);</span><br><span class="line"><span class="keyword">delete</span> obj.<span class="property">z</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">info</span>(obj.<span class="property">z</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的执行结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="title class_">Book</span> = &#123;</span><br><span class="line">  <span class="attr">price</span>: <span class="number">32</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">const</span> book = <span class="title class_">Object</span>.<span class="title function_">create</span>(<span class="title class_">Book</span>);</span><br><span class="line">book.<span class="property">type</span> = <span class="string">&#x27;Math&#x27;</span>;</span><br><span class="line"><span class="keyword">delete</span> book.<span class="property">price</span>;</span><br><span class="line"><span class="keyword">delete</span> book.<span class="property">type</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(book.<span class="property">price</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(book.<span class="property">type</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="作用域与预编译"><a href="#作用域与预编译" class="headerlink" title="作用域与预编译"></a>作用域与预编译</h4><ol>
<li>下面的程序会报错吗？如果不会，输出结果分别是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">sayHello</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(name);</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(age);</span><br><span class="line">    <span class="keyword">var</span> name = <span class="string">&quot;Tom&quot;</span>;</span><br><span class="line">    <span class="keyword">let</span> age = <span class="number">18</span>;</span><br><span class="line">&#125; </span><br><span class="line"><span class="title function_">sayHello</span>();</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面的程序i的打印结果分别是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++) &#123;</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function"><span class="params">_</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(i)</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++) &#123;</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function"><span class="params">_</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(i)</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a);</span><br><span class="line"><span class="keyword">var</span> a = <span class="string">&#x27;a&#x27;</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(b);</span><br><span class="line"><span class="keyword">let</span> b = <span class="string">&#x27;b&#x27;</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> foo = <span class="string">&quot;Hello&quot;</span>;</span><br><span class="line">(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="keyword">var</span> bar = <span class="string">&quot; World&quot;</span>;</span><br><span class="line">    <span class="title function_">alert</span>(foo + bar);</span><br><span class="line">&#125;)();</span><br><span class="line"><span class="title function_">alert</span>(foo + bar);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="number">10</span>;</span><br><span class="line">(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(a)</span><br><span class="line">    a = <span class="number">5</span></span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">window</span>.<span class="property">a</span>)</span><br><span class="line">    <span class="keyword">var</span> a = <span class="number">20</span>;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(a)</span><br><span class="line">&#125;)()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面代码的输出结果是:</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> a = <span class="number">10</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">runFunction</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="keyword">const</span> a = <span class="number">20</span></span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;inside&#x27;</span>, a)</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">runFunction</span>()</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;outside&#x27;</span>, a)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请描述打印结果并说明原因</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&quot;use strict&quot;</span></span><br><span class="line"><span class="keyword">var</span> name = <span class="string">&#x27;Jay&#x27;</span></span><br><span class="line"><span class="keyword">var</span> person = &#123;</span><br><span class="line">    <span class="attr">name</span>: <span class="string">&#x27;Wang&#x27;</span>,</span><br><span class="line">    <span class="attr">pro</span>: &#123;</span><br><span class="line">        <span class="attr">name</span>: <span class="string">&#x27;Michael&#x27;</span>,</span><br><span class="line">        <span class="attr">getName</span>: <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">name</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(person.<span class="property">pro</span>.<span class="property">getName</span>)</span><br><span class="line"><span class="keyword">var</span> people = person.<span class="property">pro</span>.<span class="property">getName</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">people</span>())</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的结果是：</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span>&gt;</span>1<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span>&gt;</span>2<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span>&gt;</span>3<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">li</span>&gt;</span>4<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">var</span> elements = <span class="variable language_">document</span>.<span class="title function_">getElementsByTagName</span>(<span class="string">&quot;li&quot;</span>);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">for</span> (<span class="keyword">var</span> i=<span class="number">0</span>;i&lt;elements.<span class="property">length</span>;i++)&#123;</span></span><br><span class="line"><span class="language-javascript">    elements[i].<span class="property">onclick</span> =<span class="keyword">function</span>(<span class="params"> </span>)&#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="title function_">alert</span>(i); </span></span><br><span class="line"><span class="language-javascript">    &#125;;</span></span><br><span class="line"><span class="language-javascript">&#125;</span></span><br><span class="line"><span class="language-javascript"></span></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的输出结果是</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">compute</span>(<span class="number">10</span>,<span class="number">100</span>);</span><br><span class="line"><span class="keyword">var</span> compute = <span class="keyword">function</span>(<span class="params">A,B</span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">info</span>(A * B) ;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">compute</span>(<span class="params">A,B</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">info</span>(A + B);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">compute</span>(<span class="params">A,B</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">info</span>((A + B)*<span class="number">2</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">compute</span>(<span class="number">2</span>,<span class="number">10</span>);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面程序的执行结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">meili</span>()</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">meili</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;meili&quot;</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">mogu</span>()</span><br><span class="line"><span class="keyword">var</span> mogu = <span class="keyword">function</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;mogu&quot;</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>下面两个代码片段输出结果有什么区别？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 片段1</span></span><br><span class="line"><span class="title function_">check</span>(<span class="string">&#x27;first&#x27;</span>);</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">check</span>(<span class="params">ars</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(ars);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 片段2</span></span><br><span class="line"><span class="title function_">check</span>(<span class="string">&#x27;second&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> check= <span class="keyword">function</span>(<span class="params">ars</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(ars);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="ES6-1"><a href="#ES6-1" class="headerlink" title="ES6"></a>ES6</h3><h4 id="对象"><a href="#对象" class="headerlink" title="对象"></a>对象</h4><ol>
<li>下面代码的输出结果是？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> student = &#123;<span class="attr">name</span>: <span class="string">&#x27;ZhangSan&#x27;</span>&#125;</span><br><span class="line"><span class="title class_">Object</span>.<span class="title function_">defineProperty</span>(student, <span class="string">&#x27;age&#x27;</span>, &#123;<span class="attr">value</span>: <span class="number">22</span>&#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(student)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Object</span>.<span class="title function_">keys</span>(student))</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="generator"><a href="#generator" class="headerlink" title="generator"></a>generator</h4><ol>
<li>下列程序的输出结果是多少？为什么？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> * <span class="title function_">cb</span>(<span class="params">x, y</span>) &#123;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="title class_">Math</span>.<span class="title function_">ceil</span>(x); i &lt;= y; i++) &#123;</span><br><span class="line">        <span class="keyword">yield</span> i;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> a = <span class="title function_">cb</span>(<span class="number">6</span>, <span class="number">9</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a.<span class="title function_">next</span>());</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a.<span class="title function_">next</span>());</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="扩展运算符"><a href="#扩展运算符" class="headerlink" title="扩展运算符"></a>扩展运算符</h4><ol>
<li>下面程序的输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">fn</span>(<span class="params">...args</span>) &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="keyword">typeof</span> args);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">fn</span>(<span class="number">21</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="promise-1"><a href="#promise-1" class="headerlink" title="promise"></a>promise</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Promise</span>.<span class="title function_">reject</span>(<span class="number">0</span>)</span><br><span class="line">       .<span class="title function_">catch</span>(<span class="function"><span class="params">e</span> =&gt;</span> e)</span><br><span class="line">       .<span class="title function_">catch</span>(<span class="function"><span class="params">e</span> =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(e))</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="class"><a href="#class" class="headerlink" title="class"></a>class</h4><ol>
<li>请写出下面ES6代码编译后所生成的ES5代码</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Person</span> &#123;</span><br><span class="line">     <span class="title function_">constructor</span> (name) &#123;</span><br><span class="line">          <span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line">     &#125;</span><br><span class="line">     greet () &#123;</span><br><span class="line">          <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">`Hi, my name is <span class="subst">$&#123;<span class="variable language_">this</span>.name&#125;</span>`</span>);</span><br><span class="line">     &#125;</span><br><span class="line">     greetDelay (time) &#123;</span><br><span class="line">          <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">               <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">`Hi, my name is <span class="subst">$&#123;<span class="variable language_">this</span>.name&#125;</span>`</span>);</span><br><span class="line">          &#125;, time);</span><br><span class="line">     &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="标签模板"><a href="#标签模板" class="headerlink" title="标签模板"></a>标签模板</h4><ol>
<li>下面程序的输出结果是多少？</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">getPersonInfo</span> (one, two, three) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(one)</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(two)</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(three)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">const</span> person = <span class="string">&#x27;Lydia&#x27;</span></span><br><span class="line"><span class="keyword">const</span> age = <span class="number">21</span></span><br><span class="line">getPersonInfo <span class="string">`<span class="subst">$&#123;person&#125;</span> is <span class="subst">$&#123;age&#125;</span> years old`</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="module"><a href="#module" class="headerlink" title="module"></a>module</h4><ol>
<li>请写出index里面的输出结果</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// module.js</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> () =&gt; <span class="string">&quot;Hello world&quot;</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> name = <span class="string">&quot;nowcoder&quot;</span></span><br><span class="line"><span class="comment">// index.js</span></span><br><span class="line"><span class="keyword">import</span> * <span class="keyword">as</span> data <span class="keyword">from</span> <span class="string">&quot;./module&quot;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(data)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>有a.js和b.js两个文件，请写出b文件中代码的输出</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// a.js</span></span><br><span class="line"><span class="keyword">let</span> a = <span class="number">1</span></span><br><span class="line"><span class="keyword">let</span> b = &#123;&#125;</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;    </span><br><span class="line">a = <span class="number">2</span>    </span><br><span class="line">b.<span class="property">b</span> = <span class="number">2</span></span><br><span class="line">&#125;, <span class="number">100</span>)</span><br><span class="line"><span class="variable language_">module</span>.<span class="property">exports</span> = &#123; a, b &#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// b.js</span></span><br><span class="line"><span class="keyword">const</span> a = <span class="built_in">require</span>(<span class="string">&#x27;./a&#x27;</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a.<span class="property">a</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a.<span class="property">b</span>)</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;    </span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(a.<span class="property">a</span>)    </span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(a.<span class="property">b</span>)</span><br><span class="line">&#125;, <span class="number">500</span>)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="其他-4"><a href="#其他-4" class="headerlink" title="其他"></a>其他</h3><ol>
<li>输出结果是：</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;box1&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;box2&quot;</span>&gt;</span></span><br><span class="line">        content</span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> $ = <span class="variable language_">document</span>.<span class="property">querySelector</span>.<span class="title function_">bind</span>(<span class="variable language_">document</span>);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> box1 = $(<span class="string">&#x27;#box1&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> box2 = $(<span class="string">&#x27;#box2&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">box1.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span>&#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box1 true&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">true</span>);</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">box1.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span>&#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box1 false&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">false</span>);</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">box2.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span>&#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box2 true&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">true</span>);</span></span><br><span class="line"><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">box2.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span>&#123;</span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box2 false&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">false</span>);</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>输出结果是：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="keyword">function</span> (<span class="params"></span>) &#123; </span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">fn1</span>(<span class="params"> value </span>) &#123;</span><br><span class="line">        <span class="title function_">alert</span>( value );</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">fn2</span>(<span class="params"> value </span>) &#123;</span><br><span class="line">        <span class="title function_">fn1</span>(<span class="string">&quot;A&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">var</span> callbacks = $.<span class="title class_">Callbacks</span>();</span><br><span class="line">    callbacks.<span class="title function_">add</span>( fn1 ); </span><br><span class="line">    callbacks.<span class="title function_">fire</span>( <span class="string">&quot;B&quot;</span> );</span><br><span class="line">    callbacks.<span class="title function_">add</span>( fn2 ); </span><br><span class="line">    callbacks.<span class="title function_">fire</span>( <span class="string">&quot;C&quot;</span> );</span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>实现在p元素后添加“Hello World!”，则横线处应使用的方法为(      )？</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span> <span class="attr">src</span>=<span class="string">&quot;/jquery/jquery.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">            $(<span class="variable language_">document</span>).<span class="title function_">ready</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                $(<span class="string">&quot;button&quot;</span>).<span class="title function_">click</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span></span><br><span class="line"><span class="language-javascript">                    $(<span class="string">&quot;&lt;b&gt;Hello World!&lt;/b&gt;&quot;</span>).<span class="title function_">______</span>(<span class="string">&quot;p&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">                &#125;);</span></span><br><span class="line"><span class="language-javascript">            &#125;);</span></span><br><span class="line"><span class="language-javascript">        </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span>&gt;</span>This is a paragraph.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span>&gt;</span>This is another paragraph.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">button</span>&gt;</span>在每个p元素的结尾添加内容<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>输出结果是：</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;box1&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;box2&quot;</span>&gt;</span></span><br><span class="line">    content</span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> $ = <span class="variable language_">document</span>.<span class="property">querySelector</span>.<span class="title function_">bind</span>(<span class="variable language_">document</span>);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> box1 = $(<span class="string">&#x27;#box1&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> box2 = $(<span class="string">&#x27;#box2&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">box1.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box1 true&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">true</span>);</span></span><br><span class="line"><span class="language-javascript">box1.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box1 false&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">false</span>);</span></span><br><span class="line"><span class="language-javascript">box2.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box2 true&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">true</span>);</span></span><br><span class="line"><span class="language-javascript">box2.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;box2 false&#x27;</span>);</span></span><br><span class="line"><span class="language-javascript">&#125;, <span class="literal">false</span>);</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol>
<li>请选择下面代码输出1的次数</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> vm = <span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;  </span><br><span class="line"><span class="attr">el</span>: <span class="string">&#x27;#example&#x27;</span>,  </span><br><span class="line"><span class="attr">data</span>: &#123;    </span><br><span class="line">    <span class="attr">message</span>: <span class="string">&#x27;Hello&#x27;</span>  </span><br><span class="line">&#125;,  </span><br><span class="line"><span class="attr">computed</span>: &#123;    </span><br><span class="line">    <span class="attr">test</span>: <span class="keyword">function</span> (<span class="params"></span>) &#123;      </span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>)      </span><br><span class="line">        <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="property">message</span>    </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;,  </span><br><span class="line"><span class="attr">created</span>: <span class="keyword">function</span> (<span class="params"></span>)&#123;    </span><br><span class="line">        <span class="variable language_">this</span>.<span class="property">message</span> = <span class="string">&#x27;World&#x27;</span>    </span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++) &#123;        </span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">test</span>)    </span><br><span class="line">        &#125;  </span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>手写简化版:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">// 防抖函数</span><br><span class="line">const debounce = (fn, delay) =&gt; &#123;</span><br><span class="line">  let timer = null;</span><br><span class="line">  return (...args) =&gt; &#123;</span><br><span class="line">    clearTimeout(timer);</span><br><span class="line">    timer = setTimeout(() =&gt; &#123;</span><br><span class="line">      fn.apply(this, args);</span><br><span class="line">    &#125;, delay);</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>适用场景：</p>
<ul>
<li>按钮提交场景：防止多次提交按钮，只执行最后提交的一次</li>
<li>服务端验证场景：表单验证需要服务端配合，只执行一段连续的输入事件的最后一次，还有搜索联想词功能类似</li>
</ul>
<p>生存环境请用lodash.debounce</p>
<h2 id="实现节流函数（throttle）"><a href="#实现节流函数（throttle）" class="headerlink" title="实现节流函数（throttle）"></a>实现节流函数（throttle）</h2><p>防抖函数原理:规定在一个单位时间内，只能触发一次函数。如果这个单位时间内触发多次函数，只有一次生效。</p>
<p>&#x2F;&#x2F; 手写简化版</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">// 节流函数</span><br><span class="line">const throttle = (fn, delay = 500) =&gt; &#123;</span><br><span class="line">  let flag = true;</span><br><span class="line">  return (...args) =&gt; &#123;</span><br><span class="line">    if (!flag) return;</span><br><span class="line">    flag = false;</span><br><span class="line">    setTimeout(() =&gt; &#123;</span><br><span class="line">      fn.apply(this, args);</span><br><span class="line">      flag = true;</span><br><span class="line">    &#125;, delay);</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>适用场景：</p>
<ul>
<li>拖拽场景：固定时间内只执行一次，防止超高频次触发位置变动</li>
<li>缩放场景：监控浏览器resize</li>
<li>动画场景：避免短时间内多次触发动画引起性能问题</li>
</ul>
<h2 id="深克隆（deepclone）"><a href="#深克隆（deepclone）" class="headerlink" title="深克隆（deepclone）"></a>深克隆（deepclone）</h2><p>简单版：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">const newObj = JSON.parse(JSON.stringify(oldObj));</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>局限性：</p>
<ol>
<li>他无法实现对函数 、RegExp等特殊对象的克隆</li>
<li>会抛弃对象的constructor,所有的构造函数会指向Object</li>
<li>对象有循环引用,会报错</li>
</ol>
<p>面试版:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * deep clone</span><br><span class="line"> * @param  &#123;[type]&#125; parent object 需要进行克隆的对象</span><br><span class="line"> * @return &#123;[type]&#125;        深克隆后的对象</span><br><span class="line"> */</span><br><span class="line">const clone = parent =&gt; &#123;</span><br><span class="line">  // 判断类型</span><br><span class="line">  const isType = (obj, type) =&gt; &#123;</span><br><span class="line">    if (typeof obj !== &quot;object&quot;) return false;</span><br><span class="line">    const typeString = Object.prototype.toString.call(obj);</span><br><span class="line">    let flag;</span><br><span class="line">    switch (type) &#123;</span><br><span class="line">      case &quot;Array&quot;:</span><br><span class="line">        flag = typeString === &quot;[object Array]&quot;;</span><br><span class="line">        break;</span><br><span class="line">      case &quot;Date&quot;:</span><br><span class="line">        flag = typeString === &quot;[object Date]&quot;;</span><br><span class="line">        break;</span><br><span class="line">      case &quot;RegExp&quot;:</span><br><span class="line">        flag = typeString === &quot;[object RegExp]&quot;;</span><br><span class="line">        break;</span><br><span class="line">      default:</span><br><span class="line">        flag = false;</span><br><span class="line">    &#125;</span><br><span class="line">    return flag;</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  // 处理正则</span><br><span class="line">  const getRegExp = re =&gt; &#123;</span><br><span class="line">    var flags = &quot;&quot;;</span><br><span class="line">    if (re.global) flags += &quot;g&quot;;</span><br><span class="line">    if (re.ignoreCase) flags += &quot;i&quot;;</span><br><span class="line">    if (re.multiline) flags += &quot;m&quot;;</span><br><span class="line">    return flags;</span><br><span class="line">  &#125;;</span><br><span class="line">  // 维护两个储存循环引用的数组</span><br><span class="line">  const parents = [];</span><br><span class="line">  const children = [];</span><br><span class="line"></span><br><span class="line">  const _clone = parent =&gt; &#123;</span><br><span class="line">    if (parent === null) return null;</span><br><span class="line">    if (typeof parent !== &quot;object&quot;) return parent;</span><br><span class="line"></span><br><span class="line">    let child, proto;</span><br><span class="line"></span><br><span class="line">    if (isType(parent, &quot;Array&quot;)) &#123;</span><br><span class="line">      // 对数组做特殊处理</span><br><span class="line">      child = [];</span><br><span class="line">    &#125; else if (isType(parent, &quot;RegExp&quot;)) &#123;</span><br><span class="line">      // 对正则对象做特殊处理</span><br><span class="line">      child = new RegExp(parent.source, getRegExp(parent));</span><br><span class="line">      if (parent.lastIndex) child.lastIndex = parent.lastIndex;</span><br><span class="line">    &#125; else if (isType(parent, &quot;Date&quot;)) &#123;</span><br><span class="line">      // 对Date对象做特殊处理</span><br><span class="line">      child = new Date(parent.getTime());</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">      // 处理对象原型</span><br><span class="line">      proto = Object.getPrototypeOf(parent);</span><br><span class="line">      // 利用Object.create切断原型链</span><br><span class="line">      child = Object.create(proto);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    // 处理循环引用</span><br><span class="line">    const index = parents.indexOf(parent);</span><br><span class="line"></span><br><span class="line">    if (index != -1) &#123;</span><br><span class="line">      // 如果父数组存在本对象,说明之前已经被引用过,直接返回此对象</span><br><span class="line">      return children[index];</span><br><span class="line">    &#125;</span><br><span class="line">    parents.push(parent);</span><br><span class="line">    children.push(child);</span><br><span class="line"></span><br><span class="line">    for (let i in parent) &#123;</span><br><span class="line">      // 递归</span><br><span class="line">      child[i] = _clone(parent[i]);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    return child;</span><br><span class="line">  &#125;;</span><br><span class="line">  return _clone(parent);</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>局限性:</p>
<ol>
<li>一些特殊情况没有处理: 例如Buffer对象、Promise、Set、Map</li>
<li>另外对于确保没有循环引用的对象，我们可以省去对循环引用的特殊处理，因为这很消耗时间</li>
</ol>
<blockquote>
<p>原理详解<a href="#deepclone">实现深克隆</a></p>
</blockquote>
<h2 id="实现Event-event-bus"><a href="#实现Event-event-bus" class="headerlink" title="实现Event(event bus)"></a>实现Event(event bus)</h2><p>event bus既是node中各个模块的基石，又是前端组件通信的依赖手段之一，同时涉及了订阅-发布设计模式，是非常重要的基础。</p>
<p>简单版：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">class EventEmeitter &#123;</span><br><span class="line">  constructor() &#123;</span><br><span class="line">    this._events = this._events || new Map(); // 储存事件/回调键值对</span><br><span class="line">    this._maxListeners = this._maxListeners || 10; // 设立监听上限</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">// 触发名为type的事件</span><br><span class="line">EventEmeitter.prototype.emit = function(type, ...args) &#123;</span><br><span class="line">  let handler;</span><br><span class="line">  // 从储存事件键值对的this._events中获取对应事件回调函数</span><br><span class="line">  handler = this._events.get(type);</span><br><span class="line">  if (args.length &gt; 0) &#123;</span><br><span class="line">    handler.apply(this, args);</span><br><span class="line">  &#125; else &#123;</span><br><span class="line">    handler.call(this);</span><br><span class="line">  &#125;</span><br><span class="line">  return true;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">// 监听名为type的事件</span><br><span class="line">EventEmeitter.prototype.addListener = function(type, fn) &#123;</span><br><span class="line">  // 将type事件以及对应的fn函数放入this._events中储存</span><br><span class="line">  if (!this._events.get(type)) &#123;</span><br><span class="line">    this._events.set(type, fn);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>面试版：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br></pre></td><td class="code"><pre><span class="line">class EventEmeitter &#123;</span><br><span class="line">  constructor() &#123;</span><br><span class="line">    this._events = this._events || new Map(); // 储存事件/回调键值对</span><br><span class="line">    this._maxListeners = this._maxListeners || 10; // 设立监听上限</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 触发名为type的事件</span><br><span class="line">EventEmeitter.prototype.emit = function(type, ...args) &#123;</span><br><span class="line">  let handler;</span><br><span class="line">  // 从储存事件键值对的this._events中获取对应事件回调函数</span><br><span class="line">  handler = this._events.get(type);</span><br><span class="line">  if (args.length &gt; 0) &#123;</span><br><span class="line">    handler.apply(this, args);</span><br><span class="line">  &#125; else &#123;</span><br><span class="line">    handler.call(this);</span><br><span class="line">  &#125;</span><br><span class="line">  return true;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">// 监听名为type的事件</span><br><span class="line">EventEmeitter.prototype.addListener = function(type, fn) &#123;</span><br><span class="line">  // 将type事件以及对应的fn函数放入this._events中储存</span><br><span class="line">  if (!this._events.get(type)) &#123;</span><br><span class="line">    this._events.set(type, fn);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">// 触发名为type的事件</span><br><span class="line">EventEmeitter.prototype.emit = function(type, ...args) &#123;</span><br><span class="line">  let handler;</span><br><span class="line">  handler = this._events.get(type);</span><br><span class="line">  if (Array.isArray(handler)) &#123;</span><br><span class="line">    // 如果是一个数组说明有多个监听者,需要依次此触发里面的函数</span><br><span class="line">    for (let i = 0; i &lt; handler.length; i++) &#123;</span><br><span class="line">      if (args.length &gt; 0) &#123;</span><br><span class="line">        handler[i].apply(this, args);</span><br><span class="line">      &#125; else &#123;</span><br><span class="line">        handler[i].call(this);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125; else &#123;</span><br><span class="line">    // 单个函数的情况我们直接触发即可</span><br><span class="line">    if (args.length &gt; 0) &#123;</span><br><span class="line">      handler.apply(this, args);</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">      handler.call(this);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  return true;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">// 监听名为type的事件</span><br><span class="line">EventEmeitter.prototype.addListener = function(type, fn) &#123;</span><br><span class="line">  const handler = this._events.get(type); // 获取对应事件名称的函数清单</span><br><span class="line">  if (!handler) &#123;</span><br><span class="line">    this._events.set(type, fn);</span><br><span class="line">  &#125; else if (handler &amp;&amp; typeof handler === &quot;function&quot;) &#123;</span><br><span class="line">    // 如果handler是函数说明只有一个监听者</span><br><span class="line">    this._events.set(type, [handler, fn]); // 多个监听者我们需要用数组储存</span><br><span class="line">  &#125; else &#123;</span><br><span class="line">    handler.push(fn); // 已经有多个监听者,那么直接往数组里push函数即可</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">EventEmeitter.prototype.removeListener = function(type, fn) &#123;</span><br><span class="line">  const handler = this._events.get(type); // 获取对应事件名称的函数清单</span><br><span class="line"></span><br><span class="line">  // 如果是函数,说明只被监听了一次</span><br><span class="line">  if (handler &amp;&amp; typeof handler === &quot;function&quot;) &#123;</span><br><span class="line">    this._events.delete(type, fn);</span><br><span class="line">  &#125; else &#123;</span><br><span class="line">    let postion;</span><br><span class="line">    // 如果handler是数组,说明被监听多次要找到对应的函数</span><br><span class="line">    for (let i = 0; i &lt; handler.length; i++) &#123;</span><br><span class="line">      if (handler[i] === fn) &#123;</span><br><span class="line">        postion = i;</span><br><span class="line">      &#125; else &#123;</span><br><span class="line">        postion = -1;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    // 如果找到匹配的函数,从数组中清除</span><br><span class="line">    if (postion !== -1) &#123;</span><br><span class="line">      // 找到数组对应的位置,直接清除此回调</span><br><span class="line">      handler.splice(postion, 1);</span><br><span class="line">      // 如果清除后只有一个函数,那么取消数组,以函数形式保存</span><br><span class="line">      if (handler.length === 1) &#123;</span><br><span class="line">        this._events.set(type, handler[0]);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">      return this;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>实现具体过程和思路见<a href="#event">实现event</a></p>
</blockquote>
<h2 id="实现instanceOf"><a href="#实现instanceOf" class="headerlink" title="实现instanceOf"></a>实现instanceOf</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">// 模拟 instanceof</span><br><span class="line">function instance_of(L, R) &#123;</span><br><span class="line">  //L 表示左表达式，R 表示右表达式</span><br><span class="line">  var O = R.prototype; // 取 R 的显示原型</span><br><span class="line">  L = L.__proto__; // 取 L 的隐式原型</span><br><span class="line">  while (true) &#123;</span><br><span class="line">    if (L === null) return false;</span><br><span class="line">    if (O === L)</span><br><span class="line">      // 这里重点：当 O 严格等于 L 时，返回 true</span><br><span class="line">      return true;</span><br><span class="line">    L = L.__proto__;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="模拟new"><a href="#模拟new" class="headerlink" title="模拟new"></a>模拟new</h2><p>new操作符做了这些事：</p>
<ul>
<li>它创建了一个全新的对象</li>
<li>它会被执行[[Prototype]]（也就是__proto__）链接</li>
<li>它使this指向新创建的对象</li>
<li>通过new创建的每个对象将最终被[[Prototype]]链接到这个函数的prototype对象上</li>
<li>如果函数没有返回对象类型Object(包含Functoin, Array, Date, RegExg, Error)，那么new表达式中的函数调用将返回该对象引用</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">// objectFactory(name, &#x27;cxk&#x27;, &#x27;18&#x27;)</span><br><span class="line">function objectFactory() &#123;</span><br><span class="line">  const obj = new Object();</span><br><span class="line">  const Constructor = [].shift.call(arguments);</span><br><span class="line"></span><br><span class="line">  obj.__proto__ = Constructor.prototype;</span><br><span class="line"></span><br><span class="line">  const ret = Constructor.apply(obj, arguments);</span><br><span class="line"></span><br><span class="line">  return typeof ret === &quot;object&quot; ? ret : obj;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="实现一个call"><a href="#实现一个call" class="headerlink" title="实现一个call"></a>实现一个call</h2><p>call做了什么:</p>
<ul>
<li>将函数设为对象的属性</li>
<li>执行&amp;删除这个函数</li>
<li>指定this到函数并传入给定参数执行函数</li>
<li>如果不传入参数，默认指向为 window</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">// 模拟 call bar.mycall(null);</span><br><span class="line">//实现一个call方法：</span><br><span class="line">Function.prototype.myCall = function(context) &#123;</span><br><span class="line">  //此处没有考虑context非object情况</span><br><span class="line">  context.fn = this;</span><br><span class="line">  let args = [];</span><br><span class="line">  for (let i = 1, len = arguments.length; i &lt; len; i++) &#123;</span><br><span class="line">    args.push(arguments[i]);</span><br><span class="line">  &#125;</span><br><span class="line">  context.fn(...args);</span><br><span class="line">  let result = context.fn(...args);</span><br><span class="line">  delete context.fn;</span><br><span class="line">  return result;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>具体实现参考<a href="https://link.juejin.cn/?target=https://github.com/mqyqingfeng/Blog/issues/11">JavaScript深入之call和apply的模拟实现 </a></p>
</blockquote>
<h2 id="实现apply方法"><a href="#实现apply方法" class="headerlink" title="实现apply方法"></a>实现apply方法</h2><p>apply原理与call很相似，不多赘述</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">// 模拟 apply</span><br><span class="line">Function.prototype.myapply = function(context, arr) &#123;</span><br><span class="line">  var context = Object(context) || window;</span><br><span class="line">  context.fn = this;</span><br><span class="line"></span><br><span class="line">  var result;</span><br><span class="line">  if (!arr) &#123;</span><br><span class="line">    result = context.fn();</span><br><span class="line">  &#125; else &#123;</span><br><span class="line">    var args = [];</span><br><span class="line">    for (var i = 0, len = arr.length; i &lt; len; i++) &#123;</span><br><span class="line">      args.push(&quot;arr[&quot; + i + &quot;]&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">    result = eval(&quot;context.fn(&quot; + args + &quot;)&quot;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  delete context.fn;</span><br><span class="line">  return result;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="实现bind"><a href="#实现bind" class="headerlink" title="实现bind"></a>实现bind</h2><p>实现bind要做什么</p>
<ul>
<li>返回一个函数，绑定this，传递预置参数</li>
<li>bind返回的函数可以作为构造函数使用。故作为构造函数时应使得this失效，但是传入的参数依然有效</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">// mdn的实现</span><br><span class="line">if (!Function.prototype.bind) &#123;</span><br><span class="line">  Function.prototype.bind = function(oThis) &#123;</span><br><span class="line">    if (typeof this !== &#x27;function&#x27;) &#123;</span><br><span class="line">      // closest thing possible to the ECMAScript 5</span><br><span class="line">      // internal IsCallable function</span><br><span class="line">      throw new TypeError(&#x27;Function.prototype.bind - what is trying to be bound is not callable&#x27;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    var aArgs   = Array.prototype.slice.call(arguments, 1),</span><br><span class="line">        fToBind = this,</span><br><span class="line">        fNOP    = function() &#123;&#125;,</span><br><span class="line">        fBound  = function() &#123;</span><br><span class="line">          // this instanceof fBound === true时,说明返回的fBound被当做new的构造函数调用</span><br><span class="line">          return fToBind.apply(this instanceof fBound</span><br><span class="line">                 ? this</span><br><span class="line">                 : oThis,</span><br><span class="line">                 // 获取调用时(fBound)的传参.bind 返回的函数入参往往是这么传递的</span><br><span class="line">                 aArgs.concat(Array.prototype.slice.call(arguments)));</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">    // 维护原型关系</span><br><span class="line">    if (this.prototype) &#123;</span><br><span class="line">      // Function.prototype doesn&#x27;t have a prototype property</span><br><span class="line">      fNOP.prototype = this.prototype; </span><br><span class="line">    &#125;</span><br><span class="line">    // 下行的代码使fBound.prototype是fNOP的实例,因此</span><br><span class="line">    // 返回的fBound若作为new的构造函数,new生成的新对象作为this传入fBound,新对象的__proto__就是fNOP的实例</span><br><span class="line">    fBound.prototype = new fNOP();</span><br><span class="line"></span><br><span class="line">    return fBound;</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<blockquote>
<p>详解请移步<a href="https://link.juejin.cn/?target=https://github.com/mqyqingfeng/Blog/issues/12">JavaScript深入之bind的模拟实现 #12</a></p>
</blockquote>
<h2 id="模拟Object-create"><a href="#模拟Object-create" class="headerlink" title="模拟Object.create"></a>模拟Object.create</h2><p>Object.create()方法创建一个新对象，使用现有的对象来提供新创建的对象的__proto__。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">// 模拟 Object.create</span><br><span class="line"></span><br><span class="line">function create(proto) &#123;</span><br><span class="line">  function F() &#123;&#125;</span><br><span class="line">  F.prototype = proto;</span><br><span class="line"></span><br><span class="line">  return new F();</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="实现类的继承"><a href="#实现类的继承" class="headerlink" title="实现类的继承"></a>实现类的继承</h2><p>类的继承在几年前是重点内容，有n种继承方式各有优劣，es6普及后越来越不重要，那么多种写法有点『回字有四样写法』的意思，如果还想深入理解的去看红宝书即可，我们目前只实现一种最理想的继承方式。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">function Parent(name) &#123;</span><br><span class="line">    this.parent = name</span><br><span class="line">&#125;</span><br><span class="line">Parent.prototype.say = function() &#123;</span><br><span class="line">    console.log(`$&#123;this.parent&#125;: 你打篮球的样子像kunkun`)</span><br><span class="line">&#125;</span><br><span class="line">function Child(name, parent) &#123;</span><br><span class="line">    // 将父类的构造函数绑定在子类上</span><br><span class="line">    Parent.call(this, parent)</span><br><span class="line">    this.child = name</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">/** </span><br><span class="line"> 1. 这一步不用Child.prototype =Parent.prototype的原因是怕共享内存，修改父类原型对象就会影响子类</span><br><span class="line"> 2. 不用Child.prototype = new Parent()的原因是会调用2次父类的构造方法（另一次是call），会存在一份多余的父类实例属性</span><br><span class="line">3. Object.create是创建了父类原型的副本，与父类原型完全隔离</span><br><span class="line">*/</span><br><span class="line">Child.prototype = Object.create(Parent.prototype);</span><br><span class="line">Child.prototype.say = function() &#123;</span><br><span class="line">    console.log(`$&#123;this.parent&#125;好，我是练习时长两年半的$&#123;this.child&#125;`);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 注意记得把子类的构造指向子类本身</span><br><span class="line">Child.prototype.constructor = Child;</span><br><span class="line"></span><br><span class="line">var parent = new Parent(&#x27;father&#x27;);</span><br><span class="line">parent.say() // father: 你打篮球的样子像kunkun</span><br><span class="line"></span><br><span class="line">var child = new Child(&#x27;cxk&#x27;, &#x27;father&#x27;);</span><br><span class="line">child.say() // father好，我是练习时长两年半的cxk</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="实现JSON-parse"><a href="#实现JSON-parse" class="headerlink" title="实现JSON.parse"></a>实现JSON.parse</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var json = &#x27;&#123;&quot;name&quot;:&quot;cxk&quot;, &quot;age&quot;:25&#125;&#x27;;</span><br><span class="line">var obj = eval(&quot;(&quot; + json + &quot;)&quot;);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>此方法属于黑魔法，极易容易被xss攻击，还有一种<code>new Function</code>大同小异。</p>
<p>简单的教程看这个<a href="https://link.juejin.cn/?target=https://zhuanlan.zhihu.com/p/28049617">半小时实现一个 JSON 解析器</a></p>
<h2 id="实现Promise"><a href="#实现Promise" class="headerlink" title="实现Promise"></a>实现Promise</h2><blockquote>
<p>我很早之前实现过一版，而且注释很多，但是居然找不到了,这是在网络上找了一版带注释的，目测没有大问题，具体过程可以看这篇<a href="https://link.juejin.cn/?target=https://zhuanlan.zhihu.com/p/21834559">史上最易读懂的 Promise&#x2F;A+ 完全实现</a></p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br></pre></td><td class="code"><pre><span class="line">var PromisePolyfill = (function () &#123;</span><br><span class="line">  // 和reject不同的是resolve需要尝试展开thenable对象</span><br><span class="line">  function tryToResolve (value) &#123;</span><br><span class="line">    if (this === value) &#123;</span><br><span class="line">    // 主要是防止下面这种情况</span><br><span class="line">    // let y = new Promise(res =&gt; setTimeout(res(y)))</span><br><span class="line">      throw TypeError(&#x27;Chaining cycle detected for promise!&#x27;)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    // 根据规范2.32以及2.33 对对象或者函数尝试展开</span><br><span class="line">    // 保证S6之前的 polyfill 也能和ES6的原生promise混用</span><br><span class="line">    if (value !== null &amp;&amp;</span><br><span class="line">      (typeof value === &#x27;object&#x27; || typeof value === &#x27;function&#x27;)) &#123;</span><br><span class="line">      try &#123;</span><br><span class="line">      // 这里记录这次then的值同时要被try包裹</span><br><span class="line">      // 主要原因是 then 可能是一个getter, 也也就是说</span><br><span class="line">      //   1. value.then可能报错</span><br><span class="line">      //   2. value.then可能产生副作用(例如多次执行可能结果不同)</span><br><span class="line">        var then = value.then</span><br><span class="line"></span><br><span class="line">        // 另一方面, 由于无法保证 then 确实会像预期的那样只调用一个onFullfilled / onRejected</span><br><span class="line">        // 所以增加了一个flag来防止resolveOrReject被多次调用</span><br><span class="line">        var thenAlreadyCalledOrThrow = false</span><br><span class="line">        if (typeof then === &#x27;function&#x27;) &#123;</span><br><span class="line">        // 是thenable 那么尝试展开</span><br><span class="line">        // 并且在该thenable状态改变之前this对象的状态不变</span><br><span class="line">          then.bind(value)(</span><br><span class="line">          // onFullfilled</span><br><span class="line">            function (value2) &#123;</span><br><span class="line">              if (thenAlreadyCalledOrThrow) return</span><br><span class="line">              thenAlreadyCalledOrThrow = true</span><br><span class="line">              tryToResolve.bind(this, value2)()</span><br><span class="line">            &#125;.bind(this),</span><br><span class="line"></span><br><span class="line">            // onRejected</span><br><span class="line">            function (reason2) &#123;</span><br><span class="line">              if (thenAlreadyCalledOrThrow) return</span><br><span class="line">              thenAlreadyCalledOrThrow = true</span><br><span class="line">              resolveOrReject.bind(this, &#x27;rejected&#x27;, reason2)()</span><br><span class="line">            &#125;.bind(this)</span><br><span class="line">          )</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">        // 拥有then 但是then不是一个函数 所以也不是thenable</span><br><span class="line">          resolveOrReject.bind(this, &#x27;resolved&#x27;, value)()</span><br><span class="line">        &#125;</span><br><span class="line">      &#125; catch (e) &#123;</span><br><span class="line">        if (thenAlreadyCalledOrThrow) return</span><br><span class="line">        thenAlreadyCalledOrThrow = true</span><br><span class="line">        resolveOrReject.bind(this, &#x27;rejected&#x27;, e)()</span><br><span class="line">      &#125;</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">    // 基本类型 直接返回</span><br><span class="line">      resolveOrReject.bind(this, &#x27;resolved&#x27;, value)()</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  function resolveOrReject (status, data) &#123;</span><br><span class="line">    if (this.status !== &#x27;pending&#x27;) return</span><br><span class="line">    this.status = status</span><br><span class="line">    this.data = data</span><br><span class="line">    if (status === &#x27;resolved&#x27;) &#123;</span><br><span class="line">      for (var i = 0; i &lt; this.resolveList.length; ++i) &#123;</span><br><span class="line">        this.resolveList[i]()</span><br><span class="line">      &#125;</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">      for (i = 0; i &lt; this.rejectList.length; ++i) &#123;</span><br><span class="line">        this.rejectList[i]()</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  function Promise (executor) &#123;</span><br><span class="line">    if (!(this instanceof Promise)) &#123;</span><br><span class="line">      throw Error(&#x27;Promise can not be called without new !&#x27;)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    if (typeof executor !== &#x27;function&#x27;) &#123;</span><br><span class="line">    // 非标准 但与Chrome谷歌保持一致</span><br><span class="line">      throw TypeError(&#x27;Promise resolver &#x27; + executor + &#x27; is not a function&#x27;)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    this.status = &#x27;pending&#x27;</span><br><span class="line">    this.resolveList = []</span><br><span class="line">    this.rejectList = []</span><br><span class="line"></span><br><span class="line">    try &#123;</span><br><span class="line">      executor(tryToResolve.bind(this), resolveOrReject.bind(this, &#x27;rejected&#x27;))</span><br><span class="line">    &#125; catch (e) &#123;</span><br><span class="line">      resolveOrReject.bind(this, &#x27;rejected&#x27;, e)()</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  Promise.prototype.then = function (onFullfilled, onRejected) &#123;</span><br><span class="line">  // 返回值穿透以及错误穿透, 注意错误穿透用的是throw而不是return，否则的话</span><br><span class="line">  // 这个then返回的promise状态将变成resolved即接下来的then中的onFullfilled</span><br><span class="line">  // 会被调用, 然而我们想要调用的是onRejected</span><br><span class="line">    if (typeof onFullfilled !== &#x27;function&#x27;) &#123;</span><br><span class="line">      onFullfilled = function (data) &#123;</span><br><span class="line">        return data</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    if (typeof onRejected !== &#x27;function&#x27;) &#123;</span><br><span class="line">      onRejected = function (reason) &#123;</span><br><span class="line">        throw reason</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    var executor = function (resolve, reject) &#123;</span><br><span class="line">      setTimeout(function () &#123;</span><br><span class="line">        try &#123;</span><br><span class="line">        // 拿到对应的handle函数处理this.data</span><br><span class="line">        // 并以此为依据解析这个新的Promise</span><br><span class="line">          var value = this.status === &#x27;resolved&#x27;</span><br><span class="line">            ? onFullfilled(this.data)</span><br><span class="line">            : onRejected(this.data)</span><br><span class="line">          resolve(value)</span><br><span class="line">        &#125; catch (e) &#123;</span><br><span class="line">          reject(e)</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;.bind(this))</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    // then 接受两个函数返回一个新的Promise</span><br><span class="line">    // then 自身的执行永远异步与onFullfilled/onRejected的执行</span><br><span class="line">    if (this.status !== &#x27;pending&#x27;) &#123;</span><br><span class="line">      return new Promise(executor.bind(this))</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">    // pending</span><br><span class="line">      return new Promise(function (resolve, reject) &#123;</span><br><span class="line">        this.resolveList.push(executor.bind(this, resolve, reject))</span><br><span class="line">        this.rejectList.push(executor.bind(this, resolve, reject))</span><br><span class="line">      &#125;.bind(this))</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  // for prmise A+ test</span><br><span class="line">  Promise.deferred = Promise.defer = function () &#123;</span><br><span class="line">    var dfd = &#123;&#125;</span><br><span class="line">    dfd.promise = new Promise(function (resolve, reject) &#123;</span><br><span class="line">      dfd.resolve = resolve</span><br><span class="line">      dfd.reject = reject</span><br><span class="line">    &#125;)</span><br><span class="line">    return dfd</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  // for prmise A+ test</span><br><span class="line">  if (typeof module !== &#x27;undefined&#x27;) &#123;</span><br><span class="line">    module.exports = Promise</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  return Promise</span><br><span class="line">&#125;)()</span><br><span class="line"></span><br><span class="line">PromisePolyfill.all = function (promises) &#123;</span><br><span class="line">  return new Promise((resolve, reject) =&gt; &#123;</span><br><span class="line">    const result = []</span><br><span class="line">    let cnt = 0</span><br><span class="line">    for (let i = 0; i &lt; promises.length; ++i) &#123;</span><br><span class="line">      promises[i].then(value =&gt; &#123;</span><br><span class="line">        cnt++</span><br><span class="line">        result[i] = value</span><br><span class="line">        if (cnt === promises.length) resolve(result)</span><br><span class="line">      &#125;, reject)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">PromisePolyfill.race = function (promises) &#123;</span><br><span class="line">  return new Promise((resolve, reject) =&gt; &#123;</span><br><span class="line">    for (let i = 0; i &lt; promises.length; ++i) &#123;</span><br><span class="line">      promises[i].then(resolve, reject)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="解析-URL-Params-为对象"><a href="#解析-URL-Params-为对象" class="headerlink" title="解析 URL Params 为对象"></a>解析 URL Params 为对象</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">let url = &#x27;http://www.domain.com/?user=anonymous&amp;id=123&amp;id=456&amp;city=%E5%8C%97%E4%BA%AC&amp;enabled&#x27;;</span><br><span class="line">parseParam(url)</span><br><span class="line">/* 结果</span><br><span class="line">&#123; user: &#x27;anonymous&#x27;,</span><br><span class="line">  id: [ 123, 456 ], // 重复出现的 key 要组装成数组，能被转成数字的就转成数字类型</span><br><span class="line">  city: &#x27;北京&#x27;, // 中文需解码</span><br><span class="line">  enabled: true, // 未指定值得 key 约定为 true</span><br><span class="line">&#125;</span><br><span class="line">*/</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">function parseParam(url) &#123;</span><br><span class="line">  const paramsStr = /.+\?(.+)$/.exec(url)[1]; // 将 ? 后面的字符串取出来</span><br><span class="line">  const paramsArr = paramsStr.split(&#x27;&amp;&#x27;); // 将字符串以 &amp; 分割后存到数组中</span><br><span class="line">  let paramsObj = &#123;&#125;;</span><br><span class="line">  // 将 params 存到对象中</span><br><span class="line">  paramsArr.forEach(param =&gt; &#123;</span><br><span class="line">    if (/=/.test(param)) &#123; // 处理有 value 的参数</span><br><span class="line">      let [key, val] = param.split(&#x27;=&#x27;); // 分割 key 和 value</span><br><span class="line">      val = decodeURIComponent(val); // 解码</span><br><span class="line">      val = /^\d+$/.test(val) ? parseFloat(val) : val; // 判断是否转为数字</span><br><span class="line"></span><br><span class="line">      if (paramsObj.hasOwnProperty(key)) &#123; // 如果对象有 key，则添加一个值</span><br><span class="line">        paramsObj[key] = [].concat(paramsObj[key], val);</span><br><span class="line">      &#125; else &#123; // 如果对象没有这个 key，创建 key 并设置值</span><br><span class="line">        paramsObj[key] = val;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125; else &#123; // 处理没有 value 的参数</span><br><span class="line">      paramsObj[param] = true;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line"></span><br><span class="line">  return paramsObj;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="模板引擎实现"><a href="#模板引擎实现" class="headerlink" title="模板引擎实现"></a>模板引擎实现</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">let template = &#x27;我是&#123;&#123;name&#125;&#125;，年龄&#123;&#123;age&#125;&#125;，性别&#123;&#123;sex&#125;&#125;&#x27;;</span><br><span class="line">let data = &#123;</span><br><span class="line">  name: &#x27;姓名&#x27;,</span><br><span class="line">  age: 18</span><br><span class="line">&#125;</span><br><span class="line">render(template, data); // 我是姓名，年龄18，性别undefined</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">function render(template, data) &#123;</span><br><span class="line">  const reg = /\&#123;\&#123;(\w+)\&#125;\&#125;/; // 模板字符串正则</span><br><span class="line">  if (reg.test(template)) &#123; // 判断模板里是否有模板字符串</span><br><span class="line">    const name = reg.exec(template)[1]; // 查找当前模板里第一个模板字符串的字段</span><br><span class="line">    template = template.replace(reg, data[name]); // 将第一个模板字符串渲染</span><br><span class="line">    return render(template, data); // 递归的渲染并返回渲染后的结构</span><br><span class="line">  &#125;</span><br><span class="line">  return template; // 如果模板没有模板字符串直接返回</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="转化为驼峰命名"><a href="#转化为驼峰命名" class="headerlink" title="转化为驼峰命名"></a>转化为驼峰命名</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">var s1 = &quot;get-element-by-id&quot;</span><br><span class="line"></span><br><span class="line">// 转化为 getElementById</span><br><span class="line"></span><br><span class="line">var f = function(s) &#123;</span><br><span class="line">    return s.replace(/-\w/g, function(x) &#123;</span><br><span class="line">        return x.slice(1).toUpperCase();</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="查找字符串中出现最多的字符和个数"><a href="#查找字符串中出现最多的字符和个数" class="headerlink" title="查找字符串中出现最多的字符和个数"></a>查找字符串中出现最多的字符和个数</h2><p>例: abbcccddddd -&gt; 字符最多的是d，出现了5次</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">let str = &quot;abcabcabcbbccccc&quot;;</span><br><span class="line">let num = 0;</span><br><span class="line">let char = &#x27;&#x27;;</span><br><span class="line"></span><br><span class="line"> // 使其按照一定的次序排列</span><br><span class="line">str = str.split(&#x27;&#x27;).sort().join(&#x27;&#x27;);</span><br><span class="line">// &quot;aaabbbbbcccccccc&quot;</span><br><span class="line"></span><br><span class="line">// 定义正则表达式</span><br><span class="line">let re = /(\w)\1+/g;</span><br><span class="line">str.replace(re,($0,$1) =&gt; &#123;</span><br><span class="line">    if(num &lt; $0.length)&#123;</span><br><span class="line">        num = $0.length;</span><br><span class="line">        char = $1;        </span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line">console.log(`字符最多的是$&#123;char&#125;，出现了$&#123;num&#125;次`);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="字符串查找"><a href="#字符串查找" class="headerlink" title="字符串查找"></a>字符串查找</h2><p>请使用最基本的遍历来实现判断字符串 a 是否被包含在字符串 b 中，并返回第一次出现的位置（找不到返回 -1）。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">a=&#x27;34&#x27;;b=&#x27;1234567&#x27;; // 返回 2</span><br><span class="line">a=&#x27;35&#x27;;b=&#x27;1234567&#x27;; // 返回 -1</span><br><span class="line">a=&#x27;355&#x27;;b=&#x27;12354355&#x27;; // 返回 5</span><br><span class="line">isContain(a,b);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">function isContain(a, b) &#123;</span><br><span class="line">  for (let i in b) &#123;</span><br><span class="line">    if (a[0] === b[i]) &#123;</span><br><span class="line">      let tmp = true;</span><br><span class="line">      for (let j in a) &#123;</span><br><span class="line">        if (a[j] !== b[~~i + ~~j]) &#123;</span><br><span class="line">          tmp = false;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      if (tmp) &#123;</span><br><span class="line">        return i;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  return -1;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="实现千位分隔符"><a href="#实现千位分隔符" class="headerlink" title="实现千位分隔符"></a>实现千位分隔符</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">// 保留三位小数</span><br><span class="line">parseToMoney(1234.56); // return &#x27;1,234.56&#x27;</span><br><span class="line">parseToMoney(123456789); // return &#x27;123,456,789&#x27;</span><br><span class="line">parseToMoney(1087654.321); // return &#x27;1,087,654.321&#x27;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">function parseToMoney(num) &#123;</span><br><span class="line">  num = parseFloat(num.toFixed(3));</span><br><span class="line">  let [integer, decimal] = String.prototype.split.call(num, &#x27;.&#x27;);</span><br><span class="line">  integer = integer.replace(/\d(?=(\d&#123;3&#125;)+$)/g, &#x27;$&amp;,&#x27;);</span><br><span class="line">  return integer + &#x27;.&#x27; + (decimal ? decimal : &#x27;&#x27;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>正则表达式(运用了正则的前向声明和反前向声明):</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">function parseToMoney(str)&#123;</span><br><span class="line">    // 仅仅对位置进行匹配</span><br><span class="line">    let re = /(?=(?!\b)(\d&#123;3&#125;)+$)/g; </span><br><span class="line">   return str.replace(re,&#x27;,&#x27;); </span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="判断是否是电话号码"><a href="#判断是否是电话号码" class="headerlink" title="判断是否是电话号码"></a>判断是否是电话号码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">function isPhone(tel) &#123;</span><br><span class="line">    var regx = /^1[34578]\d&#123;9&#125;$/;</span><br><span class="line">    return regx.test(tel);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="验证是否是邮箱"><a href="#验证是否是邮箱" class="headerlink" title="验证是否是邮箱"></a>验证是否是邮箱</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">function isEmail(email) &#123;</span><br><span class="line">    var regx = /^([a-zA-Z0-9_\-])+@([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-])+$/;</span><br><span class="line">    return regx.test(email);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="验证是否是身份证"><a href="#验证是否是身份证" class="headerlink" title="验证是否是身份证"></a>验证是否是身份证</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">function isCardNo(number) &#123;</span><br><span class="line">    var regx = /(^\d&#123;15&#125;$)|(^\d&#123;18&#125;$)|(^\d&#123;17&#125;(\d|X|x)$)/;</span><br><span class="line">    return regx.test(number);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>


<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="https://szhihao.gitee.io">孙志豪</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/js%E7%AC%94%E8%AF%95%E9%A2%98/">https://szhihao.gitee.io/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/js%E7%AC%94%E8%AF%95%E9%A2%98/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/img/%E5%A4%A9%E7%A9%BA.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/1.5%E4%B8%87%E5%AD%97%E6%A6%82%E6%8B%ACES6%E5%85%A8%E9%83%A8%E7%89%B9%E6%80%A7(%E5%B7%B2%E6%9B%B4%E6%96%B0ES2020)/"><img class="prev-cover" src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">1.5万字概括ES6全部特性(已更新ES2020)</div></div></a></div><div class="next-post pull-right"><a href="/2022/10/11/11-%E5%89%8D%E7%AB%AF%EF%BC%88CSS%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E6%8E%98%E9%87%91CSS%E5%9F%BA%E7%A1%80/"><img class="next-cover" src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">CSS基础篇</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/img/%E5%A4%B4%E5%83%8F.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">孙志豪</div><div class="author-info__description">吾日三省吾身：为人谋而不忠乎？与朋友交而不信乎？传不习乎？</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">44</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">15</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/szhihao/szhihao"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/szhihao/szhihao" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/qq_54753561" target="_blank" title="CSDN"><i class="fa fa-book-open"></i></a><a class="social-icon" href="mailto:zhihaomail@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#js%E6%A6%82%E5%BF%B5%E4%B8%8E%E7%B1%BB%E5%9E%8B%E6%A3%80%E6%B5%8B"><span class="toc-number">1.</span> <span class="toc-text">js概念与类型检测</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E5%88%A4%E6%96%AD"><span class="toc-number">2.</span> <span class="toc-text">逻辑判断</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Math"><span class="toc-number">3.</span> <span class="toc-text">Math</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">4.</span> <span class="toc-text">字符串</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#JSON"><span class="toc-number">5.</span> <span class="toc-text">JSON</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E7%BB%84"><span class="toc-number">6.</span> <span class="toc-text">数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%AD%A3%E5%88%99"><span class="toc-number">7.</span> <span class="toc-text">正则</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B6%E4%BB%96"><span class="toc-number">8.</span> <span class="toc-text">其他</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#JS%E6%B7%B1%E5%85%A5"><span class="toc-number"></span> <span class="toc-text">JS深入</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#this"><span class="toc-number">1.</span> <span class="toc-text">this</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8%E5%9F%9F-%E9%97%AD%E5%8C%85"><span class="toc-number">2.</span> <span class="toc-text">作用域(闭包)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8E%9F%E5%9E%8B%E4%B8%8E%E7%BB%A7%E6%89%BF"><span class="toc-number">3.</span> <span class="toc-text">原型与继承</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B6%E4%BB%96-1"><span class="toc-number">4.</span> <span class="toc-text">其他</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DOM%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">DOM题</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E6%B5%81"><span class="toc-number">1.</span> <span class="toc-text">事件流</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#DOM%E9%81%8D%E5%8E%86"><span class="toc-number">2.</span> <span class="toc-text">DOM遍历</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B6%E4%BB%96-2"><span class="toc-number">3.</span> <span class="toc-text">其他</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#BOM%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">BOM题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ES6%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">ES6题</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0"><span class="toc-number">1.</span> <span class="toc-text">箭头函数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#promise"><span class="toc-number">2.</span> <span class="toc-text">promise</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%A7%A3%E6%9E%84%E8%B5%8B%E5%80%BC"><span class="toc-number">3.</span> <span class="toc-text">解构赋值</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E9%80%89%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">多选题</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#JS%E5%9F%BA%E7%A1%80"><span class="toc-number"></span> <span class="toc-text">JS基础</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#JS%E6%B7%B1%E5%85%A5-1"><span class="toc-number"></span> <span class="toc-text">JS深入</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ES6"><span class="toc-number"></span> <span class="toc-text">ES6</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DOM"><span class="toc-number"></span> <span class="toc-text">DOM</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A1%AB%E7%A9%BA%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">填空题</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B1%BB%E5%9E%8B%E6%A3%80%E6%B5%8B"><span class="toc-number"></span> <span class="toc-text">类型检测</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-number">1.</span> <span class="toc-text">类型转换</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E5%88%A4%E6%96%AD-1"><span class="toc-number">2.</span> <span class="toc-text">逻辑判断</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96-3"><span class="toc-number"></span> <span class="toc-text">其他</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A8%8B%E5%BA%8F%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">程序题</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#JS%E5%9F%BA%E7%A1%80-1"><span class="toc-number"></span> <span class="toc-text">JS基础</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#JS%E6%B7%B1%E5%85%A5-2"><span class="toc-number"></span> <span class="toc-text">JS深入</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#this%E6%8C%87%E5%90%91"><span class="toc-number">1.</span> <span class="toc-text">this指向</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E5%BE%AA%E7%8E%AF"><span class="toc-number">2.</span> <span class="toc-text">事件循环</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8E%9F%E5%9E%8B%E4%B8%8E%E5%8E%9F%E5%9E%8B%E9%93%BE"><span class="toc-number">3.</span> <span class="toc-text">原型与原型链</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8%E5%9F%9F%E4%B8%8E%E9%A2%84%E7%BC%96%E8%AF%91"><span class="toc-number">4.</span> <span class="toc-text">作用域与预编译</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ES6-1"><span class="toc-number"></span> <span class="toc-text">ES6</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.</span> <span class="toc-text">对象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#generator"><span class="toc-number">2.</span> <span class="toc-text">generator</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%89%A9%E5%B1%95%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">3.</span> <span class="toc-text">扩展运算符</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#promise-1"><span class="toc-number">4.</span> <span class="toc-text">promise</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#class"><span class="toc-number">5.</span> <span class="toc-text">class</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%A0%87%E7%AD%BE%E6%A8%A1%E6%9D%BF"><span class="toc-number">6.</span> <span class="toc-text">标签模板</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#module"><span class="toc-number">7.</span> <span class="toc-text">module</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96-4"><span class="toc-number"></span> <span class="toc-text">其他</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E8%8A%82%E6%B5%81%E5%87%BD%E6%95%B0%EF%BC%88throttle%EF%BC%89"><span class="toc-number"></span> <span class="toc-text">实现节流函数（throttle）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%8B%E9%9A%86%EF%BC%88deepclone%EF%BC%89"><span class="toc-number"></span> <span class="toc-text">深克隆（deepclone）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0Event-event-bus"><span class="toc-number"></span> <span class="toc-text">实现Event(event bus)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0instanceOf"><span class="toc-number"></span> <span class="toc-text">实现instanceOf</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A8%A1%E6%8B%9Fnew"><span class="toc-number"></span> <span class="toc-text">模拟new</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAcall"><span class="toc-number"></span> <span class="toc-text">实现一个call</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0apply%E6%96%B9%E6%B3%95"><span class="toc-number"></span> <span class="toc-text">实现apply方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0bind"><span class="toc-number"></span> <span class="toc-text">实现bind</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A8%A1%E6%8B%9FObject-create"><span class="toc-number"></span> <span class="toc-text">模拟Object.create</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E7%B1%BB%E7%9A%84%E7%BB%A7%E6%89%BF"><span class="toc-number"></span> <span class="toc-text">实现类的继承</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0JSON-parse"><span class="toc-number"></span> <span class="toc-text">实现JSON.parse</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0Promise"><span class="toc-number"></span> <span class="toc-text">实现Promise</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%A3%E6%9E%90-URL-Params-%E4%B8%BA%E5%AF%B9%E8%B1%A1"><span class="toc-number"></span> <span class="toc-text">解析 URL Params 为对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E%E5%AE%9E%E7%8E%B0"><span class="toc-number"></span> <span class="toc-text">模板引擎实现</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BD%AC%E5%8C%96%E4%B8%BA%E9%A9%BC%E5%B3%B0%E5%91%BD%E5%90%8D"><span class="toc-number"></span> <span class="toc-text">转化为驼峰命名</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9F%A5%E6%89%BE%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E5%87%BA%E7%8E%B0%E6%9C%80%E5%A4%9A%E7%9A%84%E5%AD%97%E7%AC%A6%E5%92%8C%E4%B8%AA%E6%95%B0"><span class="toc-number"></span> <span class="toc-text">查找字符串中出现最多的字符和个数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%9F%A5%E6%89%BE"><span class="toc-number"></span> <span class="toc-text">字符串查找</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E7%8E%B0%E5%8D%83%E4%BD%8D%E5%88%86%E9%9A%94%E7%AC%A6"><span class="toc-number"></span> <span class="toc-text">实现千位分隔符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81"><span class="toc-number"></span> <span class="toc-text">判断是否是电话号码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%AA%8C%E8%AF%81%E6%98%AF%E5%90%A6%E6%98%AF%E9%82%AE%E7%AE%B1"><span class="toc-number"></span> <span class="toc-text">验证是否是邮箱</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%AA%8C%E8%AF%81%E6%98%AF%E5%90%A6%E6%98%AF%E8%BA%AB%E4%BB%BD%E8%AF%81"><span class="toc-number"></span> <span class="toc-text">验证是否是身份证</span></a></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/10/12/04-%E5%89%8D%E7%AB%AF%EF%BC%88%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87%EF%BC%89/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87/" title="性能优化面试题"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="性能优化面试题"/></a><div class="content"><a class="title" href="/2022/10/12/04-%E5%89%8D%E7%AB%AF%EF%BC%88%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87%EF%BC%89/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87/" title="性能优化面试题">性能优化面试题</a><time datetime="2022-10-12T12:01:36.000Z" title="Created 2022-10-12 20:01:36">2022-10-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS字符串方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS字符串方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS字符串方法">JS字符串方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS对象方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS对象方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS对象方法">JS对象方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E6%9F%A5%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS数组方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS数组方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E6%9F%A5%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS数组方法">JS数组方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/" title="开发封装函数"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="开发封装函数"/></a><div class="content"><a class="title" href="/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/" title="开发封装函数">开发封装函数</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 孙志豪</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">Search</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  Loading the Database</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="Search for Posts" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>